Group Assignment

Compare as many tool options as possible

In this case, we decide to compare three (03) options available. One where we can use a third party developed interfaceand two that allow us to generate interfases:

  1. Use of LightBlue: Being a third party app interface that function on a cellphone, it will require a board that allows Bluethooht connectivity. In this case, we used a ESP32C3 considering:
    • For this case, we will use the XIAO ESP32C3 as Bluetooth server: Here we follow what is suggested by Seedstudio, we use LightBlue app, because works with iphone, and that it is available on iphone App store
      The app allow us to use a smartphone and send out digital instructions from my phone to the microcontroler. Thus, we need to install an app to exert control over the microcontroller. Like
    • Connect the microcontroller with the input/output
    • Establish Cellphone connectivity with the microcontroller. Which means that in the App there must be the option to select the bluethooth signal that the ESP32C3 generates and connect with it. Thus any instruction could be send it
    • Thus, the code generate will need to allows input/output control using the microcontroller - app network
    • When using LightBlue you will need to:
      • Select Input/output Control Network (Generated by ESP32C3 coding)
      • Click Properties Write
      • Once there, at the top right, click on Hex (default option)
      • A new window will open, you'll have four (04) alternative to select - Hex, Octal, Binary, UTF-8 String - you need to select the one according to your programing, in our case we select UTF-8 String
      • Then, the app will take you back to Properties write and there you'll must click on Write new value
      • And there you'll need to enter the options that you consider in your programing. In this case for LED control we enter 1 to turn the LED on, and 0 to turn it off
      • 											
        #include <BLEDevice.h>
        #include <BLEUtils.h>
        #include <BLEServer.h>
        #include <BLE2902.h>
        									
        #define LED_PIN D0 // Cambia el pin según la conexión de tu LED
        #define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
        #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
        									
        BLEServer* pServer = NULL;
        BLECharacteristic* pCharacteristic = NULL;
        bool deviceConnected = false;
        									
        class MyServerCallbacks : public BLEServerCallbacks {
        	void onConnect(BLEServer* pServer) {
        	  deviceConnected = true;
        	};
        									
        	void onDisconnect(BLEServer* pServer) {
        	  deviceConnected = false;
        	}
        };
        									
        class MyCallbacks : public BLECharacteristicCallbacks {
        	void onWrite(BLECharacteristic *pCharacteristic) {
        	  std::string value = pCharacteristic->getValue();
        									
        	  if (value.length() > 0) {
        		if (value[0] == '1') {
        		  digitalWrite(LED_PIN, HIGH); // Encender el LED
        		} else if (value[0] == '0') {
        		  digitalWrite(LED_PIN, LOW); // Apagar el LED
        		}
        	  }
        	}
        };
        									
        	void setup() {
        	  Serial.begin(115200);
        	  pinMode(LED_PIN, OUTPUT);
        									
        	  BLEDevice::init("LEDControl");
        	  pServer = BLEDevice::createServer();
        	  pServer->setCallbacks(new MyServerCallbacks());
        									
        	  BLEService *pService = pServer->createService(BLEUUID(SERVICE_UUID));
        	  pCharacteristic = pService->createCharacteristic(
        			  BLEUUID(CHARACTERISTIC_UUID),
        			  BLECharacteristic::PROPERTY_WRITE
        				);
        									
        	  pCharacteristic->setCallbacks(new MyCallbacks());
        									
        	  pService->start();
        	  BLEAdvertising *pAdvertising = pServer->getAdvertising();
        	  pAdvertising->start();
        	  Serial.println("Esperando la conexión Bluetooth...");
        	}
        									
        	void loop() {
        	  if (deviceConnected) {
        		// Puedes realizar otras tareas mientras está conectado
        	  }
        	  delay(1000); // Espera para no saturar el procesador
        	}
        											
        										

    In the following image you can observe the process


    You can download the Codehere.

  2. Use ofApp Inventor : A MIT Platform is an intuitive, visual programming environment that allows to build fully functional apps for Android phones, iPhones, and Android/iOS tablets. You can decide about building and interface for your computer or for cellphone or tablet, thus, you can stablish serial, wifi or bluethooht communication. Hence, this could affect your microcontroller connectivity features. In this case, we used a ESP32C3 to build a cellphone app considering:
    • Connecting the microcontroller with the input/output
    • Developing an app to establish Cellphone connectivity with the microcontroller. In this case, we follow the steps suggested by Programador Novato:
      • Wou will need to create a new project

      • Define your app components in our case we include Device selector and 3 buttoms for output's actions to be reflected on a LCD Anger Face, Sorprised Face and Tired Face
      • Then, once in the App Inventor platform, you'll have two basic working options, User Interface and Layout
        . The first one allows you to add the components that you decide to include in your interface

        The second one allows you to organize (distribute) your components on the user interface

      • The platform allow you then to work in blocks mode in order to program your app functioning
        The image below shows the App we developed

      • To use your App, you need to:
        Run a emulation by clicking on Connect < Emulator or run the app on your cellphone (You'll need to download App Inventor throught your Playstore or AppStore) following the app instructions to scan a QR or using a number code to connect with the platform and get access to your developed App.

    You can download the Codehere.

  3. Use of Processing: is an open source integrated development environment (IDE), works as a software sketchbook and promote a language for learning how to code.you can create stunning visual and interactive experiences. You use serial data and send it to Processing using a serial library (in Processing). You can review a complete explanation of how it works with arduino in this page form Arduino Education Visualization with Arduino and Processing: This allows you to use the data from different sensors!. In this case, we used a XIAO RP2040 considering:
    • In this case, you'll need to generate a code to read the selected sensor, in our case a Hall effect sensor A13425. The code need to include display details

    • 									
      #include <Wire.h>
      #include <Adafruit_GFX.h>
      #include <Adafruit_SSD1306.h>
      
      #define SCREEN_WIDTH 128 // OLED display width, in pixels
      #define SCREEN_HEIGHT 64 // OLED display height, in pixels
      #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
       
      Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
      
      int sensorPin = 27;    // analog input pin RP2040 pin 27
      int val = 0;  // variable to store the value coming from the sensor
      
      unsigned int ADCValue;
      
      void setup() {
      
        display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
        delay(2000);
        display.clearDisplay();
        display.setTextColor(WHITE);
      
        Serial.begin(9600); // initialize serial communications
      
        pinMode(28,OUTPUT);
      }
      
      void loop() {
      
      	display.clearDisplay();
        val = analogRead(sensorPin); // read the value from the sensor
        val = map(val,0, 1023, 0, 255);
        Serial.println(val); // print value to Serial Monitor
        analogWrite(28,val);
      
        display.setTextSize(2);
        display.setCursor(0, 28);
        display.print(val);
      
        display.display();
        delay(300);
      }
      									
      								

    • Upload the program to the microcontroller
    • Generate the code for processing software that allows input/output control using the microcontroller - sensor serial network
    • When using Processing we use the following code:
    • 									
      import processing.serial.*;
      
      Serial myPort;  // Create object from Serial class
      static String val;    // Data received from the serial port
      int sensorVal = 0;
      
      void setup()
      {
        size(720, 480);
        noStroke();
        noFill();
        String portName = "COM18";// Change the number (in this case )
        to match the corresponding port number connected to your Arduino. 
      
        myPort = new Serial(this, portName, 9600);
      }
      
      void draw()
      {
        if ( myPort.available() > 0) {  // If data is available,
        val = myPort.readStringUntil('\n'); 
        try {
         sensorVal = Integer.valueOf(val.trim());
        }
        catch(Exception e) {
        ;
        }
        println(sensorVal); // read it and store it in vals!
        }  
       background(0);
        // Scale the mouseX value from 0 to 640 to a range between 0 and 175
        float c = map(sensorVal, 0, width, 0, 400);
        // Scale the mouseX value from 0 to 640 to a range between 40 and 300
        float d = map(sensorVal, 0, width, 40,500);
        fill(100, c, 0);
        ellipse(width/2, height/2, d, d);
      
        fill(255);
        textSize(30);
        text("Sensor Value: "+ sensorVal, 10, 40);
      
      
        fill(200);
        textSize(50);
        text("Sensor Value: "+ sensorVal, 10, 100);
      
       fill(150);
       noStroke();
       rect(100,200,c,20);
      }
      									
      								

    In the following image you can observe the process and interface result. We develop an interface to show a square and a circle that increase their size regarding the imput they recieve form the magnetic field detector. The images below shows how the interface change when a magnet is expose from different distances

    You can download the Code for Arduino Ide and Processing here.

Individual Assignment

Interface for managing a LED

I decided to use thonny to develop my interface. Thonny is a software that runs Python IDE. And to develop interface you can dowload a specific package (a sort of plug in) call Guizero, that allows you to get access to specific coding libraries. Guizero is designed to allow new learners to quickly and easily create Grapfic User Interfaces for their programs. This library could be use to be run also on Phyton IDE, and you can download it using the following instructions like it is explained here. We also need to install another library Pyserial to get access for the serial port and you can download it using the following instructions like it is explained here. Further, I used guizero to develop my interface, but using Thonny, following this steps:

  1. We decide to use Xiao RP2040, considering that I develop a board with a LED during Week 8.
  2. After selecting the board, I decide to develop a specific code in Arduino IDE for the microcontroller and another in Python to connect by serial the microcontroller with the interface.
  3. In this case, you'll need first to generate a code to read tunr the LED on and off. The code will need to recognize the serial imput that will come from the interface. I used the following code:
    								
    #define led 26
    
    void setup() {
      // put your setup code here, to run once:
      pinMode(led, OUTPUT);
      Serial.begin(9600);
      digitalWrite(led, LOW);
    }
    	
    void loop() {
      // put your main code here, to run repeatedly:
      if(Serial.available()>0){
    	char option = Serial.read();   
    	if(option == '1'){
    	  digitalWrite(led, HIGH);
    	}
    	else{
    	  digitalWrite(led, LOW);
    	}
      }
    }
    
    
  4. Then, connect the microcontroller to upload the Arduino IDE programing
  5. Further, we need to develop the coding for Thonny. I followed this list of steps:
    • I installed Guizero as a package within Thonny interface: Go to Tools, Manage Packages, Search for "guizero" and click on install
    • Once intalled, you'll get the following image on Thonny Intefase

    • I installed Pyserial as a package within Thonny interface: Go to Tools, Manage Packages, Search for "pyserial" and click on install
    • As a reference, suggested by my instructor, I used a book, Create Graphical User Interfaces with Python by Laura Sach and Martin O’Hanlon as a guideline. You can find the book here.

    • I used the reference on Chapter 3: "Spy Name Chooser" that explain how to add text in a window and create a function that could be activated with a buttom that will also appear in a window
    • Then, I generated the coding that allows to control the LED using the interface that send the information to the microcontroller (RP2040) throught the serial port using Thonny. I used the following python code:
      										
      from guizero import App, Text, PushButton
      import serial, time
      
      xiao = serial.Serial('COM30', 9600)
      time.sleep(1)
      
      def turn_on():    
      	xiao.write(b'1')
      	print("LED encendido")
      
      def turn_off():
      	xiao.write(b'0')
      	print("LED apagado")
      
      app = App("Interface con Arduino")
      app.bg = "white"
      
      button = PushButton(app, turn_on, text="LED ON")
      button.bg = "red"
      
      button = PushButton(app, turn_off, text="LED OFF")
      button.bg = "blue"
      
      app.display()
      xiao.close()
      										
      									
    • You need to click on Play buttom on Thonny and the interface will appear in your computer screen
    • The interface produced two buttoms, a red one to turn the LED on and blue one to turn the LED off, as shown on the image below

You can download the Arduino Ide and Thonny Programing files here.

In the following video you can observe the final result when controlling the LED


Interface for managing a ServoMotor

We used the same LED configuration but changing the code to control a microservo SG90

  1. We decide to use Xiao RP2040, considering that I develop a board to control a servomotor Week 9.
  2. After selecting the board, I decide to develop a specific code in Arduino IDE for the microcontroller and another in Python to connect by serial the microcontroller with the interface.
  3. In this case, you'll need first to generate a code to generate a 180 movement. The code will need to recognize the serial imput that will come from the interface. I used the following Arduino code:
    								
    #include <Servo.h>
    
    
    Servo myservo;  // create servo object to control a servo
    // twelve servo objects can be created on most boards
    
    void setup() {
    	  Serial.begin(9600);
    }
    
    void loop() {
    	  Serial.print("Procesos de Fabricacion Digital");
    	  Serial.println(" Arduino Mega");
    }
    								
    							
  4. Then, connect the microcontroller to upload the Arduino IDE programing
  5. Further, we need to develop the coding for Thonny. I followed this list of steps:
    • I used the same process applied for LED control
    • I generated the coding that allows to control the ServoMotor using the interface that send the information to the microcontroller (RP2040) throught the serial port using Thonny. I used the following python code:
      										
      from guizero import App, Text, PushButton
      import serial, time
      
      xiao = serial.Serial('COM30', 9600)
      time.sleep(1)
      
      def turn_on():    
      		xiao.write(b'1')
      		print("Servo 180")
      
      def turn_off():
      		xiao.write(b'0')
      		print("Servo 0")
      
      app = App("Xiao Interface")
      app.bg = "white"
      
      button = PushButton(app, turn_on, text="Servo 180")
      button.bg = "red"
      
      button = PushButton(app, turn_off, text="Servo 0")
      button.bg = "blue"
      
      app.display()
      xiao.close()
      										
      									
    • You need to click on Play buttom on Thonny and the interface will appear in your computer screen
    • The interface produced two buttoms, a red one to generate a 180° arm movement and blue one to return to 0°, as shown on the image below

You can download the Arduino Ide and Thonny Programing files here.

In the follorwing video you can observe the final result when controlling the ServoMotor