Skip to content
Snippets Groups Projects
Commit 798fbfb9 authored by Mina Mayo-Smith's avatar Mina Mayo-Smith
Browse files

Update file 02-process.md

parent c7f5faa9
No related branches found
No related tags found
No related merge requests found
Pipeline #438987 passed
......@@ -283,28 +283,13 @@ Boards:
1. [**XIAO ESP32C3**](https://wiki.seeedstudio.com/XIAO_ESP32C3_Getting_Started/)
![Alt text](<../images/FINAL PROJ/circuit_boards01.jpg>){width=300}
![Alt text](<../images/FINAL PROJ/circuit_boards03.jpg>){width=300}
![Alt text](<../images/FINAL PROJ/diagrams01.jpg>)
#### ESP32 board set up
!!! example "**ESP32** Information"
**Step 1**: Prepare Arduino IDE for Xiaos
- [ESP-WROOM-32 on Arduino ](https://www.deviceplus.com/arduino/lets-play-with-esp-wroom-32-on-arduino-environment-construction-setup-led-blinking/?fbclid=IwAR2MLQgIpNsol_VAYNStH30PhUcd88YtlfI8wNJf24LJSBCFq3KU3BKcsCg)
- [The Newbie’s Guide to Programming an ESP32 on the Arduino IDE](https://www.iottechtrends.com/program-esp32-on-arduino-ide/?fbclid=IwAR1W8dblx-idwUIDvSSKgXqxPp-xUp5z3Nx4CDEQd2OLjUCn-G3ag2rRusU)
- [Boot Mode Selection](https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/boot-mode-selection.html)
ESP-WROOM-32 is a Wi-Fi module equipped with a chip called ESP32 provided by **Espressif Systems** and capable of Wi-Fi and Bluetooth (BLE) communication. It is slightly larger than ESP-WROOM-02, but it still is small. The module also has the advantage that Arduino programs can be written (that is, the module can be used as part of Arduino), and Wi-Fi communication is supported. Read more on the ESP32 board by checking out the links above.
Steps:
1. Download ESP32 Board in Arduino IDE Library
2. Download Files
3. Download Driver
4. Upload Code to ESP32
For step 1: I am following this [link](https://www.iottechtrends.com/program-esp32-on-arduino-ide/?fbclid=IwAR1W8dblx-idwUIDvSSKgXqxPp-xUp5z3Nx4CDEQd2OLjUCn-G3ag2rRusU). I open Arduino IDE then click on File > Preferences and paste the link below to be able to install the ESP32 Board in Arduino IDE boards library.
I am following this [link](https://www.iottechtrends.com/program-esp32-on-arduino-ide/?fbclid=IwAR1W8dblx-idwUIDvSSKgXqxPp-xUp5z3Nx4CDEQd2OLjUCn-G3ag2rRusU). I open Arduino IDE then click on File > Preferences and paste the link below to be able to install the ESP32 Board in Arduino IDE boards library.
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
......@@ -314,48 +299,48 @@ Then I go to Boards Manager and install the ESP32 board by **Espressif Systems**
![Alt text](<../images/FINAL PROJ/esp32_setup01.jpg>)
For steps 2-4: I am following this [link]((https://www.deviceplus.com/arduino/lets-play-with-esp-wroom-32-on-arduino-environment-construction-setup-led-blinking/?fbclid=IwAR2MLQgIpNsol_VAYNStH30PhUcd88YtlfI8wNJf24LJSBCFq3KU3BKcsCg))
First, I download the ZIP folder from this [github website](https://github.com/espressif/arduino-esp32)
![Alt text](<../images/FINAL PROJ/esp32_setup05.jpg>)
For step 3: I download these softwares for my Driver from this [Silicon Labs](https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads) website. I downloaded the 1st and 3rd
![Alt text](<../images/FINAL PROJ/esp32_setup03.jpg>)
Now I have these downloaded folders..
I go back to **Arduino IDE** and choose my **Board** and **Port** in **_Tools_**
![Alt text](<../images/FINAL PROJ/esp32_setup02.jpg>)
Board: **XIAO_ESP32C3**
Port: For me it is **COM6** but could be different for you
For the Drivers I need to extract the Zip folders and then istall the **64bit files** for each. I managed to find the x64 one for the VCP folder.
**Step 2**: Solder pins onto XIAO boards:
![Alt text](<../images/FINAL PROJ/Drivers_install01.jpg>)
![Alt text](<../images/FINAL PROJ/Drivers_installed01.jpg>)
[image ]
VCP Driver installed!
**Step 3**: Test LED Program on xiao boards
To do this: positive leg of LED to Xiao ESP32C3's D10 pin and negative leg thru a 470ohm resistor to GND
[ pin out ]
Finally, I go back to **Arduino IDE** and choose my **Board** and **Port** in **_Tools_**
[ Picture of my set up:]
Board: **ESP32S3 Dev Module**
Port: For me it is **COM3** but could be different for you
Use the following code to see if the Xiao board can signal the LED to blink.
![Alt text](<../images/FINAL PROJ/board_port01.jpg>)
```
_.... to be continued_
// define led according to pin diagram
int led = D10;
#### XIAO-ESP32-C3 board set up
void setup() {
// initialize digital pin led as an output
pinMode(led, OUTPUT);
}
!!! example "**XIAO ESP32-C3** Information"
void loop() {
digitalWrite(led, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off
delay(1000); // wait for a second
}
- [Getting Started with Seeed Studio XIAO ESP32C3](https://wiki.seeedstudio.com/XIAO_ESP32C3_Getting_Started/)
- [Seeed Studio XIAO ESP32C3 - RISC-V tiny MCU board with Wi-Fi and Bluetooth5.0, battery charge supported, power efficiency and rich Interface](https://www.seeedstudio.com/Seeed-XIAO-ESP32C3-p-5431.html)
```
_.... to be continued_
Repeat for the second xiao.
[ video of led blinking ]
#### communication between the two boards
### **spiral four**: communication between the two boards
!!! example "Communication Between **two ESP32 mcus**"
......@@ -363,8 +348,8 @@ _.... to be continued_
![Alt text](<../images/FINAL PROJ/diagrams04.jpg>)
TX, Transmitter: Microphone sensor and Xiao on Garment
RX, Receiver: ESP32 connected to Computer Arduino IDE and TD
**TX, Transmitter**: Microphone sensor and Xiao on Garment
**RX, Receiver**: ESP32 connected to Computer Arduino IDE and TD
The two boards will communivate via a program called **_ESP-NOW_**. Tutorial above.
......@@ -374,10 +359,274 @@ I will end up running **3 pieces of code**...
2. Running the Mac Address code on the RX board > to get it's unique wireless communication ID
3. Configuring and uploading the Receiver Code to the RX board
_.... to be continued_
These are codes just to test whether the two xiao boards can communicate with each other. It does not include the data from the microphone sensor. The next spiral will include code for the microphone sensor.
#### First Code:
```
// Transmitter Code
#include <esp_now.h>
#include <WiFi.h>
#define Channel 1 // TX and RX must be on same channel
esp_now_peer_info_t slave; // stores info about slave, incl MAC Address
uint8_t data = 0; // initial data sent...unsigned integer...250 bytes or less
## PART FOUR: COMMUNICATION BETWEEN ARDUINO IDE & TD
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT);
WiFi.mode(WIFI_STA); // set TX mode as Wifi Station
esp_now_init();
esp_now_register_send_cb(OnDataSent); // run Call-back function called OnDataSent
ScanForSlave(); // find slave MAC address at specific SSID
esp_now_add_peer(&slave); // point to stored slave data...based on discovered MAC address
}
void loop() {
esp_now_send(slave.peer_addr, &data, sizeof(data)); // send to slave address, data, data length
data++;
delay(3000);
int state = digitalRead(buttonPin);
}
void ScanForSlave(){
int8_t scanResults = WiFi.scanNetworks();
for (int i = 0; i < scanResults; ++i){
String SSID = WiFi.SSID(i);
String BSSIDstr = WiFi.BSSIDstr(i);
if (SSID.indexOf("RX") == 0){ // Looks for matching network name
int mac[6];
if (6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5])){
for (int ii = 0; ii < 6; ++ii){
slave.peer_addr[ii] = (uint8_t) mac[ii];
}
}
slave.channel = Channel;
slave.encrypt = 0;
break;
}
}
}
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status){
Serial.print("I sent my data > ");
Serial.println(data);
}
```
#### Second Code:
Plug the RX board into your computer and upload this code. Then go to serial monitor and copy the digits like this:
```
//Get MAC Address Code
#include "WiFi.h"
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_MODE_STA);
Serial.println(WiFi.macAddress());
}
void loop(){}
```
Open your serial monitor.
this is what i got in the last line: this is the MAC address for the RX board: I will need these digits for when I want the TX to send information wirelessly to my RX (in the next spiral):
15:08:56.975 -> **34:85:18:03:77:7C**
#### Third Code:
```
// Receiver Code
#include <esp_now.h>
#include <WiFi.h>
#define Channel 1 // same channel as TX
uint8_t newData;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP); // set wifi to AP mode
WiFi.softAP("RX_1", "RX_1_Password", Channel, 0); // SSID that TX can recognize
esp_now_init();
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
Serial.print("I did this to data >> ");
Serial.println(newData * 5); //making use of incoming data
delay(3000);
}
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len){
Serial.print("I just received >> ");
Serial.println(*data);
memcpy(&newData, data, sizeof(newData)); //copy data from membory (memory copy) for use in loop
}
```
Now that I've tested that the TX and RX Xiao boards can communicate with one another, I want the TX to transmit microphone sensor data to the RX.
### **spiral five**: test microphone sensor with TX+RX
#### TX code
In this code I will insert my **RX board's MAC address**
the line that says "uint8_t RxMACaddress[] = {0x34, 0x85, 0x18, 0x03, 0x77, 0x7C};" is where those digits go
```
//Transmitter Code
//-----------------------------------------------------------
//ESP-NOW: Transmitter
//Ref: Random Nerd Tutorials https://randomnerdtutorials.com
//-----------------------------------------------------------
#include <esp_now.h>
#include <WiFi.h>
//-------------------------------------------------------------------------------------
uint8_t RxMACaddress[] = {0x34, 0x85, 0x18, 0x03, 0x77, 0x7C}; // mac address of MY RX, []= array of variables
#define micPin A0 //analog pin where mic outpin is connected = A0
//-------------------------------------------------------------------------------------
// type of variable called a struct , allows you to store more than one thing
typedef struct TxStruct
{
int micVal; // variable to store microphone data
}TxStruct;
TxStruct sentData;
//-------------------------------------------------------------------------------------
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) //dont mess lines 22-26
{
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
//======================================================================================
void setup()
{
Serial.begin(9600);
WiFi.mode(WIFI_STA);
//------------------------------------------------------------------------------------
if(esp_now_init() != ESP_OK)
{
Serial.println("Error initializing ESP-NOW");
return;
}
//-------------------------------------------------------------------------------------
esp_now_register_send_cb(OnDataSent);
//-------------------------------------------------------------------------------------
esp_now_peer_info_t minaRX; // name of my receiver
memcpy(minaRX.peer_addr, RxMACaddress, 6);
minaRX.channel = 0; // lines 43-49 dont mess
minaRX.encrypt = false;
//-------------------------------------------------------------------------------------
if(esp_now_add_peer(&minaRX) != ESP_OK)
{
Serial.println("Failed to add peer");
return;
}
}
//======================================================================================
void loop()
{
sentData.micVal = analogRead(micPin);
//-------------------------------------------------------------------------------------
esp_err_t result = esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData)); // lines 57- end dont mess
//-------------------------------------------------------------------------------------
if (result == ESP_OK) Serial.println("Sent with success");
else Serial.println("Error sending the data");
//-------------------------------------------------------------------------------------
delay(500);
}
```
#### RX code
```
//Receiver Code
//-----------------------------------------------------------
//ESP-NOW: Receiver
//Ref: Random Nerd Tutorials https://randomnerdtutorials.com
//-----------------------------------------------------------
#include <esp_now.h>
#include <WiFi.h>
// #include <Wire.h> // could delete
// #include <Adafruit_GFX.h> // could delete
// #include <Adafruit_SSD1306.h> // could delete
//-------------------------------------------------------------------------------------
//Adafruit_SSD1306 display(128, 64, &Wire, -1); //could delete
//-------------------------------------------------------------------------------------
typedef struct RxStruct
{
int micVal;
}RxStruct;
RxStruct receivedData;
//-------------------------------------------------------------------------------------
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len)
{
memcpy(&receivedData, incomingData, sizeof(receivedData)); //new command, copying data from memory and assigning to variable called receivedData
}
//======================================================================================
void setup()
{
Serial.begin(9600);
// if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
// {
// Serial.println(F("SSD1306 allocation failed"));
// for (;;); // Don't proceed, loop forever
// }
// display.clearDisplay();
//-------------------------------------------------------------------------------------
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) //40-47 dont mess
{
Serial.println("Error initializing ESP-NOW");
return;
}
esp_now_register_recv_cb(OnDataRecv);
}
//======================================================================================
void loop() // custom code
{
// display.setTextColor(WHITE); display.clearDisplay();
// display.setTextSize(2); display.setCursor(20,0); display.print("ESP-NOW");
// display.setCursor(10,18); display.print("POT Value");
// display.setTextSize(3); display.setCursor(25,42); display.print(receivedData.potVal);
// display.display();
//int val = map(receivedData.micVal, 4095, 0, 0, 1000);
Serial.println(receivedData.micVal);
}
```
## PART FOUR: SERIAL DATA AND AUDIO-REACTIVE VISUALS
Once i've managed to transfer my microphone sensor data from Arduino IDE to TD, I can start playing around with this data in TouchDesigner to trigger different animations.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment