#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
uint8_t data[] = "hello ";
Wire.write(data, 6); // respond with message of 6 bytes
// as expected by master
}
Master_reciever code (esp32 wroom 32)
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Serial.println("\nI2C Scanner");
}
void loop() {
Wire.requestFrom(8, 10); // request 6 bytes from slave device #8
while (Wire.available()) { //slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
This is what the serial port outputs on my esp32 (master_reciever):
I2C Scanner
h2�{{�hello h2����h2����hel6{��y�{{�
Any idea why is this happening? Everything is wired correctly
@veci, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have mastered your problem
sometimes you need to pull up to a different voltage than 5 volts, or you might need a stronger pull-up resistor for faster rise times. just a couple thoughts, there’s probably more reasons.
But aren't both boards 3.3v? I've read that while trying to figure out another way to communicate using UART. That both boards need to be the same voltage, I don't know if this applies in i2c.
I2C pins: As opposed to other Arduino Nano boards, pins A4 and A5 have an internal pull up and default to be used as an I2C Bus so usage as analog inputs is not recommended.
What does this mean, does it affect my use case?
Finally, which pull-up resistor would you choose? What do I need them to convert to and from?
Yes, both boards are 3.3V. And yes, boards in general need the same voltage; sending a 5V signal to any pin of a 3.3V board runs the risk that you damageb the 3.3V board.
In that case you might not need the external pull-up resistors.
yes, grounds are connected. Just 1 short cable apart.
UART is slower for what I've read. Also both boards need to be connected to the same pc via USB for it to work, right? And this is not possible for the finished product.
I am running a NN in the nano and I want the output to be sent as fast as possible to the esp32 since I have very limited cpu power.
What speed do you require? The hardware UART connection can be at least 115200 baud rate, and it's not clear to me if there is a higher speed possible given that the connection is Arduino/Arduino and there is no Serial monitor involved.
Also both boards need to be connected to the same pc via USB for it to work, right?
Why do you think this? As long as the grounds are connected you are just wiring TX/RX connections from the Serial1 pins.
I am running a NN in the nano and I want the output to be sent as fast as possible to the esp32 since I have very limited cpu power.
Please explain more about what you are doing with the nano33, and why the entire program can not run on the ESP32.
Hi, so I just changed the cables for the sake of it and it worked just fine.. so yeah... wtf?
I read that: Note: In order to enable serial communication, both Arduino boards must be connected to your computer via USB.
From here: https://docs.arduino.cc/tutorials/nano-33-ble-sense/UART
Didn't have time to try it myself.
Well the nano sense has all the sensors (mic and light) that I need and it's really straight forward with the Edge Impulse tool (if I use this board). Also I am using the esp32 for postprocessing + sending the results to a server. I am not sure if the esp32 board alone could keep it up... The nano can't, that's for sure.