Week 11 - Fabio Coelho Ribeiro

Prior knowledge

I've mainly worked with bluetooth modules and simple to use wireless communications devices of short range in the past (433MHz transmitter and receiver module).



Hero shot



Wired communication

For the wired communication, I'll try a new circuit with a microcontroller I never used to communicate with a LCD and an OLED Screen (both working with I2C) the value of a button.

The microcontroller used is the SEEED XIAO-nRF52840 Sense, its pins are exactly the same as the previously used SEEED XIAO-RP2040.

I didn't include the two 4k7 resistors for the I2C because, apparently, if the devices already have them, they are unnecessary and I didn't know if the devices already had them.

(Button mounted in pull-down)

Here's the final wiring :

 
                            /////////////////////////////////////
                            //////////// Code in C++ ////////////
                            /////////////////////////////////////

                            #include   // I2C library

                            #include 
                            #include                                               // OLED library
                            #define SCREEN_WIDTH 128                                                   // OLED width in pixels
                            #define SCREEN_HEIGHT 64                                                   // OLED height in pixels
                            #define OLED_RESET -1                                                      // Not used
                            #define SCREEN_ADDRESS 0x3C                                                // OLED I2C address
                            Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);  // Create OLED object

                            #include                         // LCD library
                            #include   // I2C expander
                            #define LCD_ADDR 0x27                       // LCD I2C address
                            hd44780_I2Cexp lcd;                         // Create LCD object

                            #define Button 3  // Button pin
                            int ButtonValue;  // Value of the button

                            void setup() {
                                Wire.begin();  // Initializes I2C

                                pinMode(Button, INPUT);  // Sets the button as an input

                                lcd.begin(16, 2);              // Initialize the LCD
                                lcd.setBacklight(HIGH);        // Turn on backlight
                                lcd.setCursor(0, 0);           // First line of the LCD
                                lcd.print("Button status :");  // Message

                                if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {  // Scans for the OLED adress
                                    while (1)
                                    ;
                                }
                                display.clearDisplay();               // Clears the OLED
                                display.setTextSize(1);               // Text size multiplier
                                display.setTextColor(SSD1306_WHITE);  // Color (white)
                                display.setCursor(0, 0);              // Top-left corner of the OLED
                                display.println("Button status :");   // Message
                                display.display();                    // Send buffer to OLED
                            }

                            void loop() {
                                ButtonValue = digitalRead(Button);  // Reads the value of the button

                                if (ButtonValue == 1) {                                     // If the button is pressed
                                    lcd.setCursor(0, 1);                                      // Second line of the I²C LCD screen
                                    lcd.print("Button pressed  ");                            // Message
                                    display.fillRect(0, 30, SCREEN_WIDTH, 8, SSD1306_BLACK);  // Erases a specific line
                                    display.setCursor(0, 30);                                 // Line of the OLED (X = 0, Y = 30)
                                    display.println("Button pressed");                        // Message
                                    display.display();
                                } else {                                                    // If the button is unpressed
                                    lcd.setCursor(0, 1);                                      // Second line of the I²C LCD screen
                                    lcd.print("Button unpressed");                            // Message
                                    display.fillRect(0, 30, SCREEN_WIDTH, 8, SSD1306_BLACK);  // Erases a specific line
                                    display.setCursor(0, 30);                                 // Line of the OLED (X = 0, Y = 30)
                                    display.println("Button unpressed");                      // Message
                                    display.display();                                        // Send buffer to OLED
                                }
                            }
                            

I had to use another library for the I2C LCD screen rather than the typical one because of a warning by the Arduino IDE due to compatibility problems.

Additional libraries used can be found at the Useful file(s) section.



Wireless communication

For the wireless communication, I'll use two SEEED XIAO-nRF52840 Sense to communicate between each other via BLE (Bluetooth Low Energy).

Introduction to BLE.

They are 2 PCBs, one for the inputs, which are one potentiometer and a switch and one for the outputs, which are one servomotor and one LED.

The potentiometer will control the position of the servomotor and the switch will turn on or off the LED.

  1. Wireless input PCB

  2. Wireless output PCB

Here's the final wiring :

 
                            
                            



Problem(s) met

  1. LCD screen power supply

    At first, the LCD screen was powered with 3,3V but the display wasn't bright enough so I changed to a 5V power supply with a cable (green cable) and the result was much better.

  2. Screens connectors not well placed

    When making the PCB, I tried to space out the 2 connectors of the screens so they wont touch each other but I didn't give them enough space and if I try to put both screens on their connectors, they overlap so I have to use cables for the LCD screen.



Useful file(s) (Click to download)

  1. Code for I2C screens (Arduino IDE)
  2. Libraries for I2C screens (Arduino IDE)
  3. Wired PCB (KiCad)
  4. Wireless inputs PCB (KiCad)
  5. Wired outputs PCB (KiCad)


ChatGPT prompts