Hi,
I am having an external IMU BNO055 with Nano Connect RP2040 on the i2c bus (pins A4, A5). I know there is an internal IMU on the same pins. I am not sure why it works (with 2 sensors on same pins) but I am able to read the BNO055 data and print it on serial port and/or Arduino cloud. The sample rate with Arduino cloud is not good enough, i need a sample after 5 to 10 ms, is it possible?
In order to achieve this sample rate I decided to use micropython datalogger (as I could not find any data logging in internal flash example with arduino code). The problem I faces now is the program crashes after a random number of readings.
Here is my code:
import machine
from machine import Pin
import time
from bno055 import *
# Pyboard hardware I2C- BNO055
i2c = machine.I2C(0, freq=100000)
#print(str(12c))
led = Pin(6, Pin.OUT)
imu_read = 0
readings = int(0)
imu = BNO055(i2c)
calibrated = False
if not calibrated:
calibrated = imu.calibrated()
# create a file named "data.csv"
file=open('data2.txt','a+')
file.write("data"+"\n")
time.sleep_ms(1000)
led.value(1)
while True:
led.value(0)
time.sleep_ms(100)
imu_read = 'Accel x {:5.1f} y {:5.1f} z {:5.1f}'.format(*imu.accel())
#imu_read = "This is just a test string for Flash writing"
led.value(1)
time.sleep_ms(100)
# write the reading from IMU
file.write(str(imu_read)+"\n")
readings += 1
#if 100 readings are done, finish the program
if readings >= 1000:
file.close()
readings = 0
led.value(0)
break
Result, it is writing in the file in flash is
"data
Accel x -0.8 y -0.3 z 9.4
Accel x -0.8 y -0.3 z 9.4
Hi Koepel,
I intend to make an orientation sensor for machine part that takes a sweep from -80 to +80 in 6 secs. I am happy with a sample within 1 degree but more samples better it is. I see that it is not crashing because of high sample rate as it crashes even with 1Hz sampling.
The BNO055 has a processor inside. Instead of reading the sensor, the data is presented by the internal processor.
The I2C bus is slow and is a weak bus. Can you show a photo with the wires ? The SDA and SCL should not be in a ribbon cable next to each other. The I2C bus was not designed to go through a cable. It is not that kind of bus.
Python and MicroPython are interpreted languages. They are slower than Arduino C++ code.
I suggest that you buy a sensor that is accurate and fast and has a SPI interface.
Hi Koepel,
Thanks for the answer and valuable suggestions. I have made it working now by replacing micropython with Circuitpython. I could not look into the implementation difference for i2c in these two but circuit python its quite stable.
Yes, I understand that in BNO055, it is the processing engine we communicate with and that is why I used this chip. I wanted to avoid complications in calculating the angles in this PoC phase.
The I2C cables between Nano connect and BNO055 boards are flying cables at the moment.
I am including this response for anyone stumbling upon this forum post in the future.
I was using the same setup as amiyou: two external BNO-055 IMU sensors on the same i2c bus of an Arduino Nano. Reading data worked just fine when connecting the sensors in parallel on a breadboard, so I soldered some wires together in a Y-formation to get rid of the breadboard. After this, it all went downhill. All of the sudden, the "get" functions (getQuat etc.) of the BNO-055 would never return a value, halting the loop entirely. Hours of searching on the internet resulted in nothing related to this specific sensor. As it turns out, the problem had nothing to do with the BNO-055 specifically.
As Koepel suggests, I2C is not meant for external sensors with long cables in between. My problem was solved again by simply using thicker, shorter cables and a lower clock frequency.