The pico can be programming in the Arduino IDE with the Earlephilhower or the Mbed OS for rp2040 boards. I have tried both of these Arduino cores but am unable to read I2C data from an Adafruit BNO055. The first step i took was changing the I2C pins using Wire1.setSda / Wire1.setScl to change the I2C pins. I then reduced the frequency to just 10 kHz to avoid any possible clock stretching problems and found that the address for the BNO055 was 0x29 using an I2C detecter program. I also used a multimeter and measured the voltages for the SDA and SCL pins. Upon uploading the sketch, I found that both the SDA and SCL lines started at 3.3V then went down to around 2.7V and then sprang back to 3.3V and stayed there until I disconnected the pico. This was all done using the Earlephilhower Arduino core. However, I was unable to retrieve any I2C data from this. I then tried the Mbed OS core and found that the Arduino IDE would detect the pico when i did not hold down the boot select button but when I unplugged it and held it down, I could not upload any sketch so in the end, I could not load any sketch from Mbed OS.
Anyone know how to setup an I2C device with the pi pico using Arduino IDE?
thanks
Do you use the Pico when run I2c scanner to determine address of the sensor?
Could you use the normal Arduino core for the Raspberry Pi Pico and not use Wire1 and not change the I2C pins, and not change the I2C clock, but everything as normal as possible with the normal pins for SDA and SCL. There is no special setup, it should work.
You have changed so many things, that it is impossible to know in which direction to look.
For example the I2C clock speed. The 10kHz might not be low enough to avoid clock pulse stretching. Some I2C devices have a minimal clock speed, so they might drop the I2C communication at 10kHz. There is no reason to avoid clock pulse stretching on a Raspberry Pi Pico as far as I know.
Which Operating System do you use ?
I did it with the pico plugged in
I use MacOs Monterey. By normal Arduino core do you mean Mbed OS for the pico? Also, by making all settings default, I could still not get any data from the BNO055. I tried using Arduino IDE 2.0 as well. But all of this again, was on a 3rd party core. As for the Mbed OS for the pi pico, I am unable to connect it it. I first plug in the pico and on both versions of the Arduino IDE I see that the pico is connected and I choose the correct comport. Once this fails, I unplug the pico and plug back in but this time, I press and hold the Boot select button until I can see it has appeared as a storage device.
And the sensor was found in the bus? - So the I2c on your Pico works correctly.
And why did you decide that the i2c bus on the Pico was the cause of the problem? Have you tried connecting your sensor to "regular" arduino - like Uno or Mega? Is it works?
Yes, the sensor was found on the bus. I have tried the sensor with an arduino nano and with almost no configuration, it works just fine. However, when connected to the pico, the values are always 0 for orientation in all of the axis. I am using the official Adafruit libraries for the BNO055.
Is this libraries are stated as compatible with RP2040?
Adafruit BNO055 - Arduino Reference. Here, It says that the library is compatible with all architectures.
Arduino Code | Adafruit BNO055 Absolute Orientation Sensor | Adafruit Learning System here, it also says that for any microcontroller other than an arduino, you just need to port the code.
"... just to port the code" ?
Porting code usually means understanding why it works on one architecture and not on another, then finding and fixing all the bugs.
Exactly the case.
The Adafruit BNO055 library uses the normal Arduino functions and uses the Wire library in a normal way. It should work on a Raspberry Pi Pico.
The Adafruit library can accept a different Wire object for the I2C bus pins. By default it uses the normal "Wire" object for the normal default I2C bus pins.
You try to use "Wire1" and then don't tell the Adafruit library that you want "Wire1". So the Adafruit library uses internally still "Wire".
So I say it again: Write normal code. If there is a problem with normal code, then we can try to fix that. You have gone totally haywire with your code, and there are multiple reasons why it does not work.
Paint your face as a clown, and throw everything that you can find in a oven: bananas, old newspapers, a blender, and so on. Then ask others for help why it does not look like a pizza when the oven has finished. We could tell that bananas don't belong in a pizza, but that would not help much.
For now I will use the default Arduino IDE (1.8.15) and the latest earle philhower core with Wire as my I2C bus. I have found the problem to be with the I2C address. By default, it is 0x28, which is what the Adafruit library uses.
With an I2C scanner, I found this to be 0x29 even though I haven't pulled the ADR pin on the BNO055 high which is strange. I am using GPIO pins 1 and 2 for I2C which are on the default I2C bus and not on the I2C1 bus. I changed the address in the Adafruit library and went to test, however upon holding down BootSel, the pico is not detected in any of the com ports. When I just plug in the pico without holding down BootSel, it is detected but when I go to upload the code, it just stalls. I have been experiencing these issues ever since I started with the pico and Arduino IDE. Only a moment ago, programs were uploading fine but by going to upload again and not changing anything related to the Arduino IDE, it refuses to upload the sketch. It just seems to work every now and then. Also, No other applications are using the comports, only Arduino IDE and Chrome are open. I am not sure what is causing this.
^^Here, you can see that it goes to upload but is stalling. This goes on for about 5 minutes until it says an error occurred during the sketch. Since I have not been able to find anything related to this issue, I go to help for here.
Thanks for helping me out here. Everyone's insight has been very helpful.
And of course Arduino IDE starts working again for no reason.
The fix does not work so far.
BNO055_OrientationTest.ino (1.0 KB)
^ Here is the new code that I am currently working on.
Please read the documentation of the I2c bus - it uses address least significant bit as READ/WRITE flag. So the 0x28 & 0x29 - are addresses of the same device.
if you have problems with upload - why are you asking about i2c? The download has nothing to do with the code Check the drivers you have installed to work with a Pico
You will be much more likely to get help if you post the sketch as code in the forum, pasting it into code tags. Downloading the code and opening it in the Arduino IDE is completely unnecessary work, most will just pass by and not read your code at all
// BNO055 Orientation Test
// Supported Boards: Raspberry Pi Pico
// By: JRD Propulsion
// Last Updated: 9/6/22
// Status: In Developement
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#define WIRE Wire // Defines I2C bus
Adafruit_BNO055 bno = Adafruit_BNO055(); // Defines device ID and address
void setup()
{
delay(2000);
Serial.begin(9600);
delay(5000); // Gives the BNO055 time to boot up
WIRE.begin(); // Begins I2C
!bno.begin();
delay(1000);
bno.setExtCrystalUse(true); // External crystal is used for higher accuracy
}
void loop()
{
sensors_event_t event;
bno.getEvent(&event);
Serial.print("\tX: ");
Serial.print(event.orientation.z, 4); // Prints X-axis orientation
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4); // Prints Y-axis orientation
Serial.println("");
delay(50);
}
Here Is the most normal code I code make. The extra delays are just for the serial monitor and sensor starting up because they have been picky these days. Other than that, I am using the default GPIO pins 4 and 5 for I2C and the address is selected as 0x28. The exact same code works with the nano and not the pico. I have scanned through all of the code files in the BNO055 Library and do not know of anything that would affect the connection with the pico. So I am unsure as to what to look for in the library that will change the connectivity. Also the address changes from 0x28 with the nano and 0x29 for the pico for some reason.
Why !bno.begin(); ............????