Featured image of post Test: EE - Boards | Arduino Beginners

Test: EE - Boards | Arduino Beginners

Table of contents

Feature image from Arduino - LED - Blink | Arduino Tutorial - Arduino Getting Started (Searched by arduino blink led experiment in DDG )


Burn LED

(2024-10-28)

  • I broke an LED because I connected the LED directly with 3.3 V without using a current-limiting resistor.

    • A typical current through an LED is

Can’t Upload

References:

  1. 电子教学 - 【教学】Arduino上传失败的24种解决方法 - bilibili - joyspace
    • Searched by Arduino烧录失败 in bilibili
  2. avrdude: ser_open (): can’t open device “\.\COM4”: acces denied
    • Searched by avrdude: ser_open(): can't open device "\\.\COM4": Access is denied. in DDG
  3. CH340 Windows 10 driver download | arduined.eu
    • Searched by Arduino Nano CH340 in DDG
  4. Uploading a simple sketch takes forever - arduino uno - SE
    • Searched by arduino IDE uploading long time in DDG

(2024-10-29)

Problem: Cannot upload firmware to board: Arduino Nano

  • Hardware connection: Plug USB cable barely between the Nano board and laptop.

    img

  • Board and Channel selection:

    ![img](Ardu-Test-Blink-04-USB_COM4-2024-10-29 000412.png)

  1. My own sketch cannot be uploaded to board.

    The “Uploading” reminder hangs forever, and finally the following errors prompted:

    img img

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    Sketch uses 924 bytes (3%) of program storage space. Maximum is 30720 bytes.
    Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xaa
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xaa
    ... # repeated messages
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xaa
    
  2. The official example (‘File’ -> ‘Examples’ -> ‘01.Basics’ -> ‘Blink’) cannot be uploaded either

    1
    
    avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.
    
  3. ‘Serial Plotter’ and ‘Serial Monitor’ both don’t return anything. Sometimes, it showed ‘Not connected. Select a board and a port to connect automatically.’.

    img


Adressing

  1. Install driver for CH340 chip.

    • Reasons

      1. Someone mentioned this driver in his question (r2-Forum).

      2. Video mentioned this chip (r1-bili).

        • My Nano board does have this chip.
          Back Front
          img img
      3. Kaushik mentioned that maybe I dont have the correct driver installed.

    • Actions:

      1. I checked the driver in ‘Device Manager’ before installation (r3-eu), and found it had been installed:

        img

    • Results:

      1. I didn’t install the driver right away, becaues I also noticed NoMachine (remote desktop) also use USB.
    • Analysis: Maybe the NoMachine occupies some resources?

  2. Close the remote connection of NoMachine.

    • Results:
      1. After relaunching the Arduino IDE, the ‘Uplong’ still can’t complete.
  3. Try to Update the driver, as suggested by (r3-eu)

    • Actions:

      1. Click “Update”

        img

    • Results:

      1. It’s already installed:

        img

  4. Install the driver again by using CH341SER\SETUP.EXE

    img

    • Results:

      1. Failed:

        img

  5. Quit NoMachine first, then install SETUP.EXE:

    • Actions:

      1. Quit NoMachine service:
        Tray menu Confirm quit
        img img
    • Results:

      1. Driver installation still failed.
  6. Uninstall NoMachine and restart the laptop.

    • Actions:

      1. Check the ports. There is only one port: COM3

        img

    • Results:

      1. Cannot upload the firmware.
  7. Plug the cable into the other USB slot, whose index is COM5:

    • Actions:

      1. Plug into another USB

        img

    • Results:

      1. Doesn’t work either.
  8. Reinstall the driver SETUP.EXE,

    • Results:

      1.No luck: “Driver install failure!” persists.

  9. Select another processor: ATmega328P (Old Bootloader) instead of ATmega328P

    • Reasons:

      1. Glipsed an answer that mentioned to use the old version (r4-SE)

      2. The combination of my previous trials is:

        img

    • Results:

      1. It works!

        img

      2. The driver apperas again automatically, though I didn’t install it manually.

        img

    • Conclusion:

      1. The problem is not the CH340 driver, but the processor.

LED Chaser

References:

  1. Arduino基础课程01——初始Arduino - bilibili - funcodecc

  2. Arduino Tutorial: LED Sequential Control- Beginner Project - YouTube - Drone How

    • Searched by arduino experiments flowing led in Google video

Materials:

  1. Recite the code after the first watch:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    void setup()
    {
        pinLed[] = {1,2,3,4}; // Indices of pins to be used
        numLed = 4
        // Configure pins
        // Specify Mode for pins: INPUT or OUTPUT
        // Set every pin to OUTPUT to drive an LED
        for {i=1, i<=numLed, i++}
        {
            pinMode(pinLed[i], 'OUTPUT'); // Input 2 args: pin id and mode
        }
    }
    
    void loop()
    {
        for{i=0; i<=numLed; i++}
        {
            digitalWrite(pinLed[i], HIGH); // Two levels of voltages
            delay(500);  // ms
            digitalWrite(pinLed[i], LOW);
        }
    
        for{i=numLed, i>0; i--}
        {
            digitalWrite(pinLed[i], HIGH);
            delay(500);
            digitalWrite(pinLed[i], LOW)
        }
    }
    

    My Mistakes:

    1. OUTPUT as a pinMode seems to be a global variable, NOT a string.

    2. Data types are missed when create a variable: int numLed = 4.

    3. The pin-1 of UNO cannot be set as OUTPUT? The pins used are started from pin-2: int pinLed[] = [2,3,4,5]

    4. The arguments of syntax for are separated by ; and enclosed by parentheses ( ), not curly braces. And the temporary counter i also needs declaration of data type.

    5. i is the index of the array, ranging from 0-3.

    6. Don’t forget semicolons at the end of each line;

    7. Variables used both by setup() and loop(), i.e., numLed and pinLed should be declared outside of these functions.

    8. Don’t forget current-limit resistor. There is a warning from the simulation platform (funcode.cc): “The maximum current allowed by led-node is: 0.02”


  • Rectified code for Arduino Nano:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    int pinLed[] = {10,11,12,13};
    int numLed = 4;
    
    void setup(){
      // Set the mode of each pin to OUTPUT
      for(int i=0; i<=numLed; i++){
        pinMode(pinLed[i], OUTPUT);
      }
    }
    
    void loop(){
      // From pin-2 to pin-5
      for(int i=0; i<=numLed; i++){
        digitalWrite(pinLed[i], HIGH);
        delay(500);
        digitalWrite(pinLed[i], LOW);
      }
      // From pin-5 to pin-2
      for(int i=numLed-1; i>=0; i--){
        digitalWrite(pinLed[i], HIGH);
        delay(500);
        digitalWrite(pinLed[i], LOW);
      }
    }
    

  1. Mount components onto breadboard, and upload the firmware to board.
    Circuit Demostration
    img https://i.ibb.co/PCqxrB6/Ardu-Test-Blink-Nano-Breadboard-2024-10-29-115901.gif

  1. Practice:

    Use two pins: #2 and #3 to light two LEDs alternatively. Each LED is on for 0.5 seconds and off for 0.5 seconds.

    Code:

    1. Use for to configure each pin
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    
    int pinLed[] = {2,3};
    int numLeds = 2;
    
    void setup() {
      for(int i=0; i<numLeds; i++){
        pinMode(pinLed[i], OUTPUT);
      }
    }
    
    void loop() {
      for(int i=0; i<numLeds; i++){
        digitalWrite(pinLed[i], HIGH);
        delay(500);
        digitalWrite(pinLed[i], LOW);
        delay(500);
      }
    }
    

    Simulation platform: funcode.cc

    img


Piezo

Simulation

References:

  1. Detect a Knock - Arduino Docs
  2. Piezo sensor with Arduino UNO - How does work Piezo sensor (Code and Circuit Diagram) - YouTube - uSriTu Hobby
    • Searched by Piezo electric disc experiments with Arduino in DDG video
  3. Arduino Workshop-Piezo Knock Sensor - Hackster.io
    • Found in s2

Materials:

(2024-10-25)

  1. Simulation platform:

SPI LED Array

References:

  1. MajicDesigns/MD_Parola

Notes:

(2024-10-31)

  1. A library controlling LED array using SPI interface.

Serial

References:

  1. Arduino基础课程07——串行通信 - bilibili - funcodecc
  2. Universal Asynchronous Receiver-Transmitter (UART) | Arduino Documentation
    • Searched by Arduino sends and receives character via UART in DDG
  3. serial - ‘Serial1’ was not declared in this scope - Arduino Stack Exchange
    • Searched by Arduino Serial exit status 1 Compilation error: 'Serial1' was not declared in this scope in DDG
  4. ‘Serial1’ was not declared in this scope - Arduino Forum
    • Found in s3
  5. Adding More Serial Ports to your board. - Arduino Docs
  6. Arduino项目实战_第四课_串口通信_(3)软串口与双机通信_哔哩哔哩_bilibili - 电子疯狂创客
    • Searched by Arduino nano 串口实验 site:bilibili.com in DDG

Notes:

  1. Just connect the Nano board with laptop with a USB cable, then upload the code (r1-Bili):

    1
    2
    3
    4
    5
    6
    7
    8
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      Serial.println("Hello");
      delay(1000);
    }
    

(2024-11-29)

  1. Serial1 doesn’t exist on Nano or Uno. Nano only has one serial port, called Serial.

    • I think this Serial is not only connected to pins: TX1 and RX0, but also the USB port.

    • Nano has NO pins for Serial1 r4-Forum,r2-Docs

      However, it can be instantiated with the SoftwareSerial library r3-SE to extend the RX and TX to simulate another serial port on other pins r5-Tutorial:

      1
      2
      3
      4
      5
      6
      7
      8
      
      #include <SoftwareSerial.h>
      
      SoftwareSerial Serial1(3,2); //Rx to pin D3, Tx to pin D2
      
      void setup() {
        Serial.begin(9600);    // Initialize the Serial monitor for debugging
        Serial1.begin(9600);   // Initialize Serial1 for sending data
      }
      

(2024-12-05)

  1. The SoftwareSerial is an individual serial port, which can do the complete serial function by iteself.

    • Reasons:

      1. Do not mix up the pins of the generic serial (TX1 & RX0). The following image shows two boards are connected with their SoftwareSerial r6-bili:

        img

      2. Serial.print() will send (wirite) data to the bus.

    • Actions:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      
      #include <SoftwareSerial.h>
      SoftwareSerial Sserial1(3,2); // RX, TX
      String str;
      char c;
      
      void setup() {
        Sserial1.begin(9600);
        Serial.begin(9600);
      }
      void loop() {
        /* Check the buffer of the SoftwareSerial */
        while (Sserial1.available()) {
          c = Sserial1.read(); /* read 1 byte */
          str +=c;
          if (c == '\n') {
            /* Use original serial to sent to PC */
            Serial.print(str);
            str = ""; /* Reset str */
          }
        }
      
        /* Use the SoftwareSerial to transmit str */
        while (Serial.available()) {
          c = Serial.read(); // Recv str from PC
          str += c;
          if (c == '\n') { // Ended with newline
            /* Use SoftwareSerial to sent to other dev */
            Sserial1.print(str);
            str = "";
          }
        }
      }
      
    • Results:

      1. The code in Arduino Docs is equivalent besides the additional SoftwareSerial usage.

Pinout

References:

  1. PIN number to use with arduino nano - Arduino Forum
    • Searched by arduino nano pin numbers in DDG
    • Searched by in

Notes:

  1. A pin should be referred to in the program by the number in its name.

    • Although the D1 and A1 have the same “number” 1, but they are gotten controlled with two totally different functions: digitalWrite() and analogWrite().

      The name D13 means the digital pin-13. The combination of a number plus a function digitalWrite/analogWrite is unique; there is no confusion.

      1
      2
      3
      
      int pinLed = 13;
      pinMode(pinLed, OUTPUT);
      digitalWrite(pinLed, LOW);
      
      • Do not get confused by other images labeling “pin number”, which are only for breadboard (r1-Forum), such as this image for “Nano Every”.

      For the SS pin, I should look up for D10 pin on the board and use digitalWrite() to control it:

      1
      2
      3
      
      int ssPin = 10;
      pinMode(ssPin, OUTPUT);
      digitalWrite(ssPin, LOW);
      
Built with Hugo
Theme Stack designed by Jimmy