Hello,
i'm having an issue with the Arduino, where it stops working after a few min. It's supposed to continously provide Serial-Output, though after a few min, that serial output will stop and the Jetson Nano won't receive any more data via i2c. At that point, pressing the reboot button on the arduino will make it work again for a short time If the Arduino is not connected to the jetson nano, (so all wires removed) and only connected via USB, the serial output will work continuously.
So there's 3 scenarios, where two show the faulty behavior:
arduino connected to jetson nano and pc via usb: -> Arduino will stop after some time
arduino is connected to jetson nano only: -> Arduino will stop after some time
arduino is connected only to pc via usb: Arduino will work fine
The Arduino is connected to a Jetson Nano to communicate via i2c.
Arduino -- Jetson Nano
VIN -- 5V
Ground -- Ground
A4 -- 27
A5 -- 28
Any ideas, what could be causing this issue? Considering, the issue doesn't occur, when the Arduino Nano is connected solely via USB, i was thinking, whether it could be faulty soldering points.
Below is the full code, which uses the Arduino to read distance via a tof sensor and sends that distance, whenever the jetson nano sends a request via i2c.
#include <Wire.h>
int x_mm; // distance in millimeters
unsigned short lenth_val = 0;
unsigned char i2c_rx_buf[16];
int i2cAddress = 0x04; // i2c of jetson nano
void setup() {
// initialize serial communication:
Serial.begin(9600);
Wire.begin(i2cAddress);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
}
void loop()
{
x_mm = ReadDistance();
Serial.println(x_mm);
delay(50);
}
void SensorRead(unsigned char addr,unsigned char* datbuf,unsigned char cnt)
{
unsigned short result=0;
// step 1: instruct sensor to read echoes
Wire.beginTransmission(82); // transmit to device #82 (0x52), you can also find this address using the i2c_scanner code, which is available on electroniclinic.com
// the address specified in the datasheet is 164 (0xa4)
// but i2c adressing uses the high 7 bits so it's 82
Wire.write(byte(addr)); // sets distance data address (addr)
Wire.endTransmission(); // stop transmitting
// step 2: wait for readings to happen
delay(1); // datasheet suggests at least 30uS
// step 3: request reading from sensor
Wire.requestFrom(82, cnt); // request cnt bytes from slave device #82 (0x52)
// step 5: receive reading from sensor
if (cnt <= Wire.available()) { // if two bytes were received
*datbuf++ = Wire.read(); // receive high byte (overwrites previous reading)
*datbuf++ = Wire.read(); // receive low byte as lower 8 bits
}
}
int ReadDistance(){
SensorRead(0x00,i2c_rx_buf,2);
lenth_val=i2c_rx_buf[0];
lenth_val=lenth_val<<8;
lenth_val|=i2c_rx_buf[1];
delay(10);
return lenth_val;
}
void writeString(int cm)
{
byte buf[4];
buf[0] = (byte) cm;
buf[1] = (byte) cm>>8;
buf[2] = (byte) cm>>16;
buf[3] = (byte) cm>>24;
Wire.write(buf, 4);}
void receiveEvent()
{
int x = 5; // dummy. Nothing implemented yet
}
void requestEvent()
{
//Serial.println("Request received");
writeString(x_mm);
}
Nvidia Jetson Code:
import smbus
import time
import os
from IPython.display import clear_output
bus = smbus.SMBus(0) # Nvidia Jetson i2c bus. SDA 27, SCL 28
address = 0x04 # arduino i2c-address
def readNumber():
number = bus.read_byte_data(address, 0)
return number
while True:
number = readNumber()
print(number, " cm")
time.sleep(1)