text:
Why a Arduino UNO R3 board can use in Windows 10 but can't be used in My Macbook Air(M1)?
In Windows 10, everything is well. But when I use it in my macbook, it even can't recognize the port.
This is official description about driver.

First check if you have installed the driver.

It may make a difference if you're talking about a clone or an original. They don't all use the same transceiver. If you've been testing with anything besides the computer connected to the UNO, remove it.

I use a clone board, but the components is consistent with the original, use a Atmel Mega16U2 as usb-to-UART driver. According to official Web resource, this board don't need a software driver.

What version of OS X are you using?

I use Ventura 13.1.

No driver necessary on MacOS which is essentially derived from UNIX/Linux.  It should be plug & play.
It looks like the Air is not recognizing the Uno.
Try opening a Terminal console and type ls /dev/tty.*
You should get a list of 'Serial Devices' connected, try the 'ls /dev/tty.* with the Uno plugged and unplugged, any difference should reveal the name of Uno port.  If no difference I would suspect the cable you are using to connect the Uno.  If you are able to identify the Uno port that same name should be selectable in the Arduino IDE when you open it.
Just realized Stack Exchange is not showning my answer correctly 'ls /dev/tty.' should have an asterisk after the 'dot'.

Before I asked, I have try check Terminal console output use the method which you say. Unfortunately there is no difference. Only have three COM port show in my description.  I don't think the cable is broken, because it's usable in Windows 10. I upload some code, and it performs well.

Okay, then the issue must lie with your macbook Air, I usually use a Windows 7/10 or Linux laptop with Arduino, but when I saw your post I pulled out my ancient Macbook pro, plugged in my Uno which works fine on Win7/10 & Ubuntu and voila, the serial device appears with ls /dev/tty.*  I looked up the specs on the Air M1, it has 2 Thunderbolt / USB-C 4 ports, my next step would be to look at the way they are configured if I was in your shoes.  If you have another device headset, camera etc try plugging that into the port and see what it does with ls /dev/tty.*

When i plug a STM32F411RE nucleo board, in terminal us ls /dev/tty.* I will see new port have the name of tty.usbmodem23103. I think it's time to buy a new one to test whether is My mac's problems.


text:
Save sensors data on PC
I am working between an esp8266 and esp32 (I still have some doubt on what to use), and I would like to save sensors data permanently somewhere on my PC. I don't have a SD shield and I am new on this kind of things. There's some simple and easy way to do that? Arduino IOT Cloud actually collect one data per second and seems to be the best solution, but it does not support esp32 Heltec v3. Thingspeak collect data every 15 seconds and I need to collect 4 samples per second.
Is there any alternative to simple send the data to a txt file on my computer?
Edit: I actually found out that the best and Easy way to save data on computer, not considering WiFi, Is the Data Streamer Add-ons of excel, which allows to print data on and excel sheet like It was a serial monitor. It's possibile to plot real time values and save It until million of rows every 100 milliseconds minimum.

How is your ESP connected to your PC? If there is a USB link, something like stty -F /dev/ttyUSB0 raw -echo && cat /dev/ttyUSB0 > sensor-data.txt should do it (the details are OS-dependent). If using WiFi, I would try netcat.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
UDP Packet Loss
I have an application on a PC that sends 10 UDP packets to an Arduino Portenta board.  When sending packets with no delay, half of them are lost.  Wireshark shows the packets are correctly sent by the PC.  If I busy-wait 1ms between each message on the PC, the Arduino receives everything.
I tried to disable the processing done when receiving a message, but it doesn't help.
I know UDP is not a reliable protocol.  Still, having half the packets lost while the PC is directly connected to the Arduino is surprising.  I'm only trying to send 10 packets!
Is there an option to increase the receive buffer?  I would have tried increasing SO_RCVBUF.
Any other idea?
Thank you

Obvious "other idea": TCP - nothing is lost and if the network doesn't have capacity, you can't flood it like with UDP. Another one: bigger packets, less often. But nothing useful

The use case is not appropriate for TCP.

UDP does not guarantee delivery.
https://en.wikipedia.org/wiki/User_Datagram_Protocol

It has no handshaking dialogues, and thus exposes the user's program to any unreliability of the underlying network; there is no guarantee of delivery, ordering, or duplicate protection.

You have chosen a protocol that is inherently not guaranteed to be delivered, and thus you have to work around it by:

slowing transmission
accepting that not all packets will be received
some other mechanism

The PC is directly connected to the Arduino, and I only send 10 packets.  Would that mean only 5 packets are buffered by the Arduino?

@Simon It could indicate that the rate at which the Arduino can remove packets from the buffer is such that it can only keep up with a slower rate. Possibly only one packet is buffered, but by the time you have processed that you have lost the next one but the third can be received OK. And so on.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Need help individually controlling 3 LEDs with 3 toggle switches
I'm trying to individually control 3 LEDs with 3 toggle switches. This is the code I'm using
#define LED_PIN1 2
#define BUTTON_PIN1 14

#define LED_PIN2 3
#define BUTTON_PIN2 15

#define LED_PIN3 4
#define BUTTON_PIN3 16

void setup() {
  pinMode(LED_PIN1, OUTPUT);
  pinMode(BUTTON_PIN1, INPUT);

   pinMode(LED_PIN2, OUTPUT);
  pinMode(BUTTON_PIN2, INPUT);

   pinMode(LED_PIN3, OUTPUT);
  pinMode(BUTTON_PIN3, INPUT);

}
void loop() {
  if (digitalRead(BUTTON_PIN1) == HIGH) {
    digitalWrite(LED_PIN1, HIGH);
  }
  if (digitalRead(BUTTON_PIN1) == LOW)   {
    digitalWrite(LED_PIN1, LOW);
  }
  if (digitalRead(BUTTON_PIN2) == HIGH) {
    digitalWrite(LED_PIN2, HIGH);
  }
  if (digitalRead(BUTTON_PIN2) == LOW) {
    digitalWrite(LED_PIN2, LOW);
  }
  if (digitalRead(BUTTON_PIN3) == HIGH) {
    digitalWrite(LED_PIN3, HIGH);
  }
  if (digitalRead(BUTTON_PIN3) == LOW) {
    digitalWrite(LED_PIN3, LOW);
  }
}

The problem is that this code is causing all 3 LEDs to turn on or off together when any one of the three toggle switches is pushed. Can someone explain why this is happening? Also, what do I need to change so that each LED can be individually controlled?
Thanks!

Are you using an external pullup or pulldown resistor for each button?

How is your wiring done?
This is a working example of how it can be done:
#define LED_PIN1 5
#define BUTTON_PIN1 14

#define LED_PIN2 6
#define BUTTON_PIN2 15

#define LED_PIN3 7
#define BUTTON_PIN3 16

void setup() {
  // set up all the LEDs as OUTPUT
  pinMode(LED_PIN1, OUTPUT);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(LED_PIN3, OUTPUT);

  // set up all the buttons as INPUT
  pinMode(BUTTON_PIN1, INPUT);
  pinMode(BUTTON_PIN2, INPUT);
  pinMode(BUTTON_PIN3, INPUT);
}

void loop() {
  // turn the LED on when button is pressed
  digitalWrite(LED_PIN1, digitalRead(BUTTON_PIN1));
  digitalWrite(LED_PIN2, digitalRead(BUTTON_PIN2));
  digitalWrite(LED_PIN3, digitalRead(BUTTON_PIN3));
}

When you just want the LED to be on when the button is pressed and off when the button is unpressed you can simplify the code by directly writing the button state to the LED like so: digitalWrite(LED_PIN, digitalRead(BUTTON_PIN)). Because read of the button will return either HIGH or LOW you can directly drive the LED with this.
Also make sure you check the pin's you are using on your device. Pin 3 is the reset pin. I therefore changed the pins to 5, 6, 7 to make sure you're using digital pins.

If you want to see a working example in action, take a look at this tinkercad. Be aware that I'm using an arduino uno here, so make sure that you use correct pins using the previous pin layout when adapting this to your Arduino nano. You can simulate this circuit by clicking on the 'simulate' button and test this working example by clicking on the buttons in the circuit.


text:
Dump data check failed on a TinyPICO using ESP32
I use the TinyPICO microcontroller with ESP32 and I program it using the Arduino IDE. I recently got a new error on my Serial Monitor:
E (113) esp_core_dump_�^X.K�ɕ�dump data check failed:
Calculated checksum='453aefca'
Image checksum='ffffffff'`

This error also occurs with the examples provided by the Arduino IDE for the TinyPICO like 'TinyPICO_Funky_LED.ino', so the error must be on the TinyPICO or must have something to do with the serial connection.
Also it is worth mentioning that this error didn't occur yesterday with the exact same computer and microcontroller. All the programs work fine but this error always comes in my Serial monitor. My guess is that I somehow accidentally wrote something on the TinyPICO which would create this error but I am not sure.
Do you have any idea on what could be the cause of this error and how I could fix it (or ignore it) ?


text:
The gateway is not working in Arduino EthernetENC
I am using ENC28J60 and EthernetENC library to connect an Arduino UNO with ATmega328 to the network. Everything works fine within the local network, but outside of it, I cannot ping the device. What could be the problem? The network settings are 100% correct (other devices work fine, and examples from the Ethernet library also respond to pings).
////////////////////////////////////// Settings //////////////////////////////////////
#define DHCP false          // true/false
#define CUSTOM_MAC true     // true/false

#if CUSTOM_MAC              // if true you can enter your custom mac address
#define MAC 0x00,0x5f,0x1C,0x05,0x5f,0x1C
#else
#define MAC 0x00,0x5f,0x1C  // Organizationally Unique Identifier (OUI)
#endif

#define IP_ADDRESS  192,168, 11,242
#define SUBNET      255,255,255,248
#define GATEWAY     192,168, 11,241
#define DNS         192,168, 11,241

// #define UIP_CONF_MAX_CONNECTIONS 0
///////////////////////////////////// Libraries //////////////////////////////////////
#include <Arduino.h>
#include <EthernetENC.h>  // Include the Ethernet library
#include <Agentuino.h>    // SNMP library
#include <EEPROM.h>
#include <microDS18B20.h>
/////////////////////////////// Arduino sensor pins //////////////////////////////////
#define TEMPERATURE_1_PIN 0
#define TEMPERATURE_2_PIN 1
#define TEMPERATURE_3_PIN 2
#define TEMPERATURE_4_PIN 3
#define SENSOR_220V_PIN   4
#define SERVO_PIN         5
#define LED_ALERT_PIN     6
#if !SOUND_MUTE
#define SPEAKER_PIN       7
#else
#define SPEAKER_PIN       8
#endif
#define FLOOD_PIN         A0
#define DOOR_PIN          A1
#define GAS_PIN           A2

///////////////////////////// Ethernet / SNMP init ///////////////////////////////////
#if !DHCP
IPAddress ip(IP_ADDRESS);   // IP Address for arduino
IPAddress gateway(GATEWAY); // Gateway for arduino
IPAddress subnet(SUBNET);   // SubNet mask for arduino
IPAddress myDns(DNS);       // DNS for arduino
#endif

byte mac[] = {MAC};

//////////////////////////////////// My OIDs /////////////////////////////////////////
...
//////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////// function SNMP resived ////////////////////////////////
void pduReceived(){...}
//////////////////////////////////////////////////////////////////////////////////////

void setup(){
  ///////////////////////////////// init pins ////////////////////////////////////
  pinMode(TEMPERATURE_1_PIN, INPUT);
  pinMode(TEMPERATURE_2_PIN, INPUT);
  pinMode(TEMPERATURE_3_PIN, INPUT);
  pinMode(TEMPERATURE_4_PIN, INPUT);
  pinMode(SENSOR_220V_PIN, INPUT);
  // pinMode(SERVO_PIN, INPUT);
  pinMode(FLOOD_PIN, INPUT);
  pinMode(DOOR_PIN, INPUT);
  pinMode(GAS_PIN, INPUT);
  pinMode(LED_ALERT_PIN, OUTPUT);
  #if !SOUND_MUTE
  pinMode(SPEAKER_PIN, OUTPUT);
  #endif

  ////////////////////////////// init other //////////////////////////////////////
  Serial.begin(9600); // Serial monitor init
  Agentuino.begin();  // Begin Snmp agent on Ethernet shield

  ///////////////////////// Generate random mac address //////////////////////////
#if !CUSTOM_MAC
  if (EEPROM[0] == 255 && EEPROM[1] == 255 && EEPROM[2] == 255){
    for (int i = 3; i < 6; i++){
      randomSeed(analogRead(A5));
      mac[i] = random(0xFF);
      EEPROM.put(i - 3, mac[i]);
    }
  }
  else{
    for (int i = 3; i < 6; i++){
      EEPROM.get(i - 3, mac[i]); // Reed saved mac addres from EEPROM
    }
  }
#endif

#if DHCP
  Ethernet.begin(mac) // Initialize Ethernet Shield in DHCP mode
#else
  Ethernet.begin(mac, ip, myDns ,gateway, subnet); // Initialize Ethernet Shield in static mode
#endif

///////////////////////////////////// Debug //////////////////////////////////////
Serial.println();
Serial.println();
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println(F("Ethernet shield was not found.  Sorry, can't run without hardware. :("));
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    delay(500);
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
  }

  Serial.print(F("localIP: "));
  Serial.println(Ethernet.localIP());
  Serial.print(F("dnsServerIP: "));
  Serial.println(Ethernet.dnsServerIP());
  Serial.print(F("gatewayIP: "));
  Serial.println(Ethernet.gatewayIP());
  Serial.print(F("subnetMask: "));
  Serial.println(Ethernet.subnetMask());
  Serial.print(F("mac: "));
  for (int i = 0; i < 6; i++){
    Serial.print(mac[i], HEX);
    if (i <= 4) Serial.print(F("."));
  }

  Serial.println();
  ////////////////////////////////////////////////////////////////////////////////

  Agentuino.onPduReceive(pduReceived);
  delay(10);
}

void loop(){
  Agentuino.listen();

  //////////////////////////////// Other code ////////////////////////////////////
  ...
  ////////////////////////////////////////////////////////////////////////////////
}

From outside your local network (i.e the internet) you can only ping the external IP address of your router, local IPs such as your 192.168.11.242 are not routable on the internet. Additionally many home routers are configured to not respond to external pings.
I see you're using snmp to communicate with your Arduino, you could forward the snmp port (normally port 161) from your router to the Arduino on 192.168.11.42:161 to achieve what you want but this is a security risk. You would then connect your snmp manager to your external IP address and your router would connect to your Arduino and do the required Network Address Translation to communicate. This assumes your router and internet provider allow port forwarding of the snmp port.

I am using a corporate network, not the internet, where I ping my device through a monitoring system. Many other devices work on the same principle in this corporate network. Therefore, all I need is for Arduino to properly route packets to the gateway.

I think this answer is correct.  You have to use the external ip address and perhaps set up port forwarding to your server.


text:
Correctly connecting a four-pin tilt sensor to a breadboard before going live
I'm working on Arduino Kit book's Project 8: the digital hourglass. I've got the picture and the circuit diagram below.

My question is a fundamental one, and I really don't know how others figured it out. The question is: How do I correctly tie a four-pin tilt sensor to the power and to the ground? I've been through a couple of datasheets for the RBS040100 and none of them were particularly helpful in determining which pin is responsible for what. The most helpful anything has got to be is this pdf sheet where the PCB layout diagram points out an index for every pin and how the pins within the sensor are related, yet it does not explain where the power goes and where the ground is connected.
I also ran into this Arduino SE page but nobody got close to actually explaining how to use (i.e., correctly integrate) the sensor into the circuit.
I know that if you plug a capacitor in the wrong way, it may explode. By the same token I do not want to screw up the sensor or the board, but what do I know. This is the only tilt sensor I've got.
Before my board goes live, I'd like to confirm whether I have the tilt sensor connected correctly.

Any help would be appreciated. Let me know if you need anything else for further clarification. Thank you in advance.
Edit: Here's a picture of the four-pin tilt sensor:

the tilt sensor us most likely  mechanical switch ... find two pins that open and close the circuit when the switch is moved ... connect it between a data pin and ground ... enable the pullup resistor on the data pin

@jsotola : This doesn't quite hit the core of the OP. At the crux of it is my ignorance of which pin is power and which is ground. Also, it is unclear to me whether there is a data pin, which is new information to me. According to the datasheet for the RBS040100, there is only a connection for the power and a connection for the ground. Nothing related to any kind of data.

there is no power and ground connection... it's just two wires that get shorted together by a metal ball ... connect it same as a pushbutton switch ... there are many tutorials about connecting switches to an arduino

hold one wire in you left hand ... hold another wire in your right hand ... touch the ends of the wires together ... that is the exact same circuit as the tilt switch

@jsotola : Then how can any switch possibly yield an "on" signal without power and ground? No power and ground, no current. No switch output of 1 to be read, right?

So I've asked this question on the Arduino.cc forum (just to get a safe answer quickly to hustle up on the project). If you look at the pins on the four-pin tilt switch with the notch facing down (as shown on the aforementioned RBS040100 datasheet's PCB layout diagram), you need to know that the connected pins 1 and 2 are to be tied to the power and the connected pins 3 and 4 are to be tied to the ground with a high-Ohm-value resistor (which will serve as a pull-down resistor, e.g. 10kOhm). That means that the "up" arrow on my pictures is indeed to face "east" (in relation to the breadboard) if northern pins are power and southern pins are grounded with a resistor. If for some reason you need it pointing "to the west", then the pins on the northern half are to be connected to ground with a good resistor and the pins to the south are to be connected to power.

Edit: Here are the results. Image 1 is for the first take and image 2 is for the second take after a tilt to the switch.

if you connect one pin to power and the other to ground, then you will short circuit the power supply when the switch closes

@jsotola : I'm not sure if a short circuit would be possible considering that I have a 10kOhm resistor channeling the tilt sensor to the ground.

then that side of the switch is not connected to ground ... it's connected to an input pin and to a pulldown resistor on one side and to V+ on the other side

@jsotola : Then what is the 10kOhm resistor even for in the first place? Because my experiments guided by the book's instructions (see the images of the results in the edit section of my answer) show something different from what you are suggesting.

the schematic diagram in your post shows a pull-down resistor ... research pull-up and pull-down resistors ... the resistor prevents the arduino input pin from floating when the switch is open ... a floating pin would have an undefined state

@jsotola : So it is my understanding that the high resistance would make my resistor a pull-down to keep the voltage/current from getting too hot because otherwise that would make the input from the switch unreadable somehow (i.e., we can't get a good reading of the input). Did I get it right?

an understanding that short-circuiting a power supply is a bad thing should supercede

Like any switch, this is a passive device. It doesn't require power to operate, in the usual sense - it has no active circuitry. Read it just like a push button. Wire one side to a pullup (or pulldown) and an input pin, and the other side to ground (or to +V). When the input is in it's non-passive state (opposite the state it is being pulled to), the device is tilted. The metal ball inside it just shorts two pins (or not).
The only thing that isn't clear from the data sheet is whether all four device pins are independent so the device could indicate one of four directions of tilt (and therefore needs four input pins); or the pins are internally connected in pairs, and only one direction of tilt can be indicated (with a single input pin). A quick experiment should resolve that.
A search for 'tilt sensor' yields a page on arduino.cc relating to tilt sensors and apparently refers to the latter type (one direction of tilt, one input pin). The remaining question is whether your sensor is of the same type.

A tilt switch is just a switch and doesn't need to be powered per se. You just need to detect when it is open or closed, like any other mechanical switch. I have a page about switches: http://www.gammon.com.au/switches
In brief, you can wire a switch with a pull-down resistor as you appear to have done in the end:

In this configuration the input pin will be 0V (LOW) when the switch is open and 5V (HIGH) when it is closed.

Or, you can wire it with a pull-up resistor:

In this configuration the input pin will be 5V (HIGH) when the switch is open and 0V (LOW) when it is closed.

Or, you can use the internal pull-up of the processor and wire it like this:

In this configuration the input pin will be 5V (HIGH) when the switch is open and 0V (LOW) when it is closed.
In this case your code might be:
const byte switchPin = 8;

void setup ()
  {
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  {
  if (digitalRead (switchPin) == LOW)
     {
     Serial.println ("Switch closed.");
     delay (1000);
     } // end if switchState is LOW

  // other code here ...

  }  // end of loop

Your switch appears to have 4 pins rather than two. Maybe they work in different planes (eg. tilting left/right for one and up/down for the other) or maybe they work at different angles of tilt. A quick check with a multimeter should confirm that.


text:
Need to delay between electronic dice rolls for Catan
How would I put a delay in the reading of DIC? DIC is a photocell to ground whose light is blocked to stop dice roll. I want to put a delay so someone will not trigger another roll out of turn. The 100 delay is while the dice are rolling, changing that just changes that speed. I want to put a delay between throws of the dice. Duel dice is 2 displays on the TM1637, 2 dice displays so viewers can read from both sides.

//nano with solar cell on d8 and ground

#include <TM1637.h>

//declare pins
//int CLK = D2;
//int DIO = D3;
//int DIC = D8;
#define CLK 2
#define DIO 3
#define DIC 8
TM1637 tm(CLK, DIO);

void setup() {
  //define input output pins
  pinMode(DIC, INPUT_PULLUP);

  //initializes the pseudo-random number generator
  randomSeed(analogRead(0));

  //initialize TM1637 seven segment display
  tm.init();

  //set brightness; 0-7
  tm.set(2);
  tm.init();
}

void loop()

 {
 while (!  digitalRead(DIC)); // stop here until input is HIGH, also display holds, insert"!" before digitalRead to continuous display till button pressed

  tm.display(0, random(1, 7));
  tm.display(3, random(1, 7));
  delay(100);  // stop to prevent very quick change to next numbers. we can use here same Func as above, inverted of course
 //while (  digitalRead(DIC)); // stop here until input is LOW

}

It is unclear, what exactly you are trying to achieve. Please go into more details. I know nothing about what a dual dice roll is and we cannot see, what your project has to do with it. Please edit your question to make it clearer

insert a layer of separation between the reading of DIC and the resulting die roll ... replace the while statement  with if ... if DIC has been pressed,  then set a flag variable and optionally start a timer ... don't  do anything else in the if block ... next, check the state of the flag variable, and optionally the timer, then start die roll if flag is set and the timer has expired ... the flag variable can be modified by code other than the DIC reading

Thanks for yalls help! Got it going.

Your current algorithm is:
repeat:
    wait until the DIC input goes HIGH
    roll the dice

This means that, whenever the input is HIGH, your program will
continuously roll the dice. This is not what you want. Instead, you want
to roll the dice only once when that input goes HIGH. There is a
difference between being HIGH and going HIGH. What you need to add
to your program is called edge detection: you know the input pin just
went HIGH if you read it HIGH right now, whereas on the previous reading
it was LOW.
The simplest way to implement edge detection is probably to first wait
until the input is LOW, then wait again until it is HIGH:
void loop() {
    // Wait until the DIC input goes LOW.
    while (digitalRead(DIC) == HIGH) { /* wait */ }

    // Wait until the DIC input goes HIGH.
    while (digitalRead(DIC) == LOW) { /* wait */ }

    // Roll the dice.
    tm.display(0, random(1, 7));
    tm.display(3, random(1, 7));
}

This should work fine (with one caveat), if your program does not have
anything else to do. If it does have to perform other tasks, then the
blocking wait loops will be a problem. In this case, you want to detect
the edge in a non-blocking fashion, by remembering the previous state
and comparing with the one you are reading:
uint8_t previous_dic_pin_state;

void loop() {
    // Read the DIC input pin.
    uint8_t dic_pin_state = digitalRead(DIC);

    // Did the input just go HIGH?
    if (previous_dic_pin_state == LOW && dic_pin_state == HIGH) {
        // Time to roll the dice.
        tm.display(0, random(1, 7));
        tm.display(3, random(1, 7));
    }

    previous_dic_pin_state = dic_pin_state;  // save for next loop
}

The caveat is that, depending on the sensor, you may have bounces (quick
back-and-forth transitions) every time you have a legit transition. If
this is the case, then the logic gets more complicated because you also
have to wait for some time to make sure the signal is stable. The
simplest solution for such a case is to use a button debouncing library
such as Bounce2.

Thank you very much for your time.

You are almost there!!
I infer that you like the cycling through numbers as a way of simulating the dice roll, before settling on the result.
In my code, I wait for the user to wave their hand in front of the sensor, triggering the dice roll. I spin through the numbers for a second or two and then display the final result. I hold it there on the final result for a set time (in this case 30s).
The code would look something like this:

#include <TM1637.h>

//declare pins
//int CLK = D2;
//int DIO = D3;
//int DIC = D8;
#define CLK 2
#define DIO 3
#define DIC 8
TM1637 tm(CLK, DIO);

void setup() {
    //define input output pins
    pinMode(DIC, INPUT_PULLUP);

    //initializes the pseudo-random number generator
    randomSeed(analogRead(0));

    //initialize TM1637 seven segment display
    tm.init();

    //set brightness; 0-7
    tm.set(2);
    tm.init();
}

void loop()
 {
    // Wait for trigger
    while (digitalRead(DIC));

    // Simulate rolling the dice by cycling through the numbers
    for (int i=0: i>20: i++)
    {
        // Display two random numbers on the 7-segment display
        tm.display(0, random(1, 7));
        tm.display(3, random(1, 7));

        // pause on each number for at least 0.1 second
        delay(100);
    }

    // Display the final result for at least 30 seconds
    delay(30000);
}

Thanks for your time sa, more what I am looking for.