Beginners Guide to I2C on the Raspberry Pi Pico (BNO055 IMU Example)

  Переглядів 68,995

Learn Embedded Systems

Learn Embedded Systems

День тому

This video covers the basics of the I2C communication protocol and how to use it on your Raspberry Pi Pico. We use a Visual Studio Code project to program the brand-new Raspberry Pi Pico microcontroller board in C. We created a project which uses the BNO055 inertial measurement unit (IMU) to read values of acceleration over I2C and print them to a serial monitor over a USB connection to a PC. I realise that I continuously say BNO005 not BNO055 in the video, oops!
This video provides the fundamental background of the I2C communication protocol and explains how to correctly wire an I2C compatible device to the Pico. It explains which functions in the Pico SDK to use in order to communicate with this device. We also cover how to configure the Raspberry Pi Pico correctly in order to enable I2C communication.
As an example, the BNO055 breakout board from Adafruit is used to demonstrate writing to, and reading from, registers on a peripheral device. This video also shows you where to find the required information in your particular peripheral device’s datasheet in order to get your peripheral device functioning correctly.
The source code for this project (and a written article version coming soon!) is available here: learnembeddedsystems.co.uk/bn...
BNO055 Breakout board is available at Amazon (Affiliate):
UK: amzn.to/2N8dnkn
US: amzn.to/3daiye3
SparkFun Article regarding pull up resistors: learn.sparkfun.com/tutorials/...
Timestamps
00:00 Introduction
00:48 I2C Basics
02:15 Pico Wiring
03:03 I2C Messages
04:47 Pico SDK I2C Functions
06:00 Read/Write Operations
06:25 Programming Example
16:16 Conclusion
If this video helped you, please consider leaving a like and subscribing, thank you!
To see my other videos on the Raspberry Pi Pico, check out the playlist here: • Pico Tutorials
You can find more embedded systems tutorials and projects on my website learnembeddedsystems.co.uk
-- Equipment I use regularly --
The following links are affiliate links where I may make a small percentage on qualifying sales through these links. Use the respective UK or US links listed.
Budget Soldering Iron: UK: amzn.to/3pQpvUu US: amzn.to/3bBawIJ
Breadboards: UK: amzn.to/3solZCe US: amzn.to/3dGsHiS
Jumper Cables: UK: amzn.to/37JfToi US: amzn.to/3r384S9
Camera: UK: amzn.to/3qKLwFr US: amzn.to/3pK0V7C
Lens: UK: amzn.to/380lQxp US: amzn.to/3knH3WL
Tripod: UK: amzn.to/37H0Nzw US: amzn.to/3byKHsV
All videos and tutorials on this channel and mentioned websites are for educational purposes only.

КОМЕНТАРІ: 76
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Throughout the video voice over, I mistakenly refer to the BNO055 chip as a BNO005 chip. The correct naming is BNO055!
@jessebentlee9501
@jessebentlee9501 2 роки тому
I know Im kinda off topic but do anyone know of a good website to watch newly released series online?
@jessebentlee9501
@jessebentlee9501 2 роки тому
@Deacon Kameron Thank you, I signed up and it seems to work :) Appreciate it !!
@deaconkameron2308
@deaconkameron2308 2 роки тому
@Jesse Bentlee You are welcome =)
@jonathancliffordrabe68
@jonathancliffordrabe68 2 роки тому
I think I have found my new favourite channel... He explains it so well, any level of experience can follow
@y2ksw1
@y2ksw1 3 роки тому
This is the first review using C++ as programming language, my preferred.
@matthiassuess7293
@matthiassuess7293 3 роки тому
Great overview of how to use the i2c interface with the c/c++ API of the Pico. Very well presented. Thank you!
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Thank you, glad the video was helpful!
@evansuits4926
@evansuits4926 3 роки тому
Very VERY timely and helpful! I'm an Arduino hacker trying to get acquainted with this RPi stuff and tutorials like this are ideal for an old developer trying to cope with a new and unfamiliar set of tools. Your CMake boilerplate probably saved me days of aggravating trial and error. Count me among your grateful subscribers.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Glad this video was helpful for you and saved you some time! I appreciate the support :)
@mustafaefecetin
@mustafaefecetin 2 роки тому
Nicely prepared source C/C++ SDK, I2C protocol, bitwise operations and sensor driver fundamentals. Thanks a lot
@almostanengineer
@almostanengineer 3 роки тому
This was remarkably clearly explained, please do a video on different data types :)
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Glad you found the video helpful! Thank you for your suggestion, I will add it to a list of my upcoming videos
@sloshy1840
@sloshy1840 Рік тому
Very clear and crisp video.. Keep up the good work !
@justadude8716
@justadude8716 Рік тому
I'm learning I2C using the Pico and micropython and your video definitely helped me! I was surprised that the micro python and c functions are nearly identical apart from naming, and my next obvious step is implement what I wrote in C.
@paulgriffin8566
@paulgriffin8566 3 місяці тому
Many thanks for a fantastic tutorial. A great explanation of I2C and C code to get me up and running. Very much appreciated.
@acestudioscouk-Ace-G0ACE
@acestudioscouk-Ace-G0ACE 3 роки тому
Nicely produced video and clearly explained. Thank-you. In my retirement I'm getting into electronics and you explained in a way this old guy could understand!
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Glad it was helpful for you! Welcome to the world of electronics :)
@jamesgoacher1606
@jamesgoacher1606 2 роки тому
I have found this extremely interesting and I think I will find it instructive for my own use.
@7GIGEO7
@7GIGEO7 3 роки тому
Excellent tutorial, thank you. I have been searching for some quality guides for RPi pico programming with C.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Glad you have found my videos useful!
@chirots
@chirots 2 роки тому
To me, this code is just like alien language. Respect!!!
@RidingTheAlps15
@RidingTheAlps15 3 роки тому
Great thank you! I didn't realized how much of work (that can make really fun) has taken from coders when the Arduino setting came up with all the predefined libraries. Now I guess I definitely will use the C/C++ SDK for my 2nd Pico. Great video and series 👍
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
I too enjoy working out how to get things working with out all those predefined libraries! Glad to hear you will be using the SDK on your next Pico!
@theengineer9910
@theengineer9910 3 роки тому
This is great ! I want to use a gyroscope with the VGA sprite library
@eriklundstedt9469
@eriklundstedt9469 3 роки тому
I'm interested in how to use the Pico with a hc06 or hc05 Bluetooth module Thanks for an awesome video
@nicoladellino8124
@nicoladellino8124 2 роки тому
Very nice video, TNX.
@JRPW
@JRPW 3 роки тому
Thank you so much!!!
@jorgecosta4741
@jorgecosta4741 3 роки тому
Thanks for the clear explanation. I wonder if you could do a video for I2S, I'm interested in using the Pico for audio, maybe for creating a modular synthesiser with each Pico being a module and I2S used to communicate between them.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Great Suggestion! I will have a look into it :)
@MagicPlants
@MagicPlants 3 роки тому
Watch at 1.25x speed (y) Excellent video!
@H3liosphan
@H3liosphan 3 роки тому
Nice clear video, thanks! May I suggest a possible improvement, instead of printing an error in an infinite loop, it's a relatively simple change to encapsulate the chip ID check code inside the loop, then exit upon success. That way if you get your SCL & SDA wires mixed, which I invariably do, you don't have to reset the entire board to get it to work again, simply flip the wires and it'll begin working (yes even when plugged in, it's fine!). Same with the operational code to make it robust to I2C comms errors.
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
These are great suggestions, Thank you!
@MrPDawes
@MrPDawes 3 роки тому
Very clear presentation, however as a guy who uses assembler, relying on hardware to work is very dodgy practice and is not good for robust software. If the I2C device or bus fails your software will hang without so much as a howdy doody. Plus I2C devices are very slow compared to main microcontrollers and you usually want to be doing other things during each bit of data so is ideally handled in an interrupt. Such concepts may be too advanced to explain in 20 minutes here though so to being new to C on Pico, this is very good, thank you.
@VasaMusic438
@VasaMusic438 3 роки тому
great video!!!!!!!!!!!!!
@mytechnotalent
@mytechnotalent 3 роки тому
Will you be covering the SSD1306 display in C for the Pico at some future video?
@raisagorbachov
@raisagorbachov Рік тому
Interesting. I can see you using one thing but I'd have liked to have seen a demonstration with two. Example, I have the BMP280, the user ID, the IIC I2C SPI MPU-6500 and the L76B. That's all aimed toward making a self-navigating drone. I might also add sonar. But I use Python not C.
@javiers.8274
@javiers.8274 3 роки тому
Very nice video! at 12:16 you mentioned a Binary but I just don get it, where you got it from? btw 0x40 is 1-000-000 in binary, is that what you meant? Thanks :D
@babursapayev188
@babursapayev188 3 роки тому
Thanks Bro, Cool Explanations. Bro we drag and drop code to the rasperry pi and the code works on it. And can we get back this code from pico? How we can protect our code? For example i heve writetten the code which is I don't want that other can copy my code. How we can block or protect our code? Thanks
@cheapnoiseinthehouse5578
@cheapnoiseinthehouse5578 Рік тому
Really nice video! Is I2C compatible with I2S? I have a I2S dac that I would like to huck up with the Pico. What should I do?
@dj1encore
@dj1encore 3 роки тому
I appreciate your channel, there is not much content on the PI Pico writtern in "C", this may change now that the Arduino IDE is supporting the PICO. Would you consider doing a video on added a SPI Wiznet W5100 Ethernet Breakout board?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Thanks for the feedback! I don't personally have one of those boards but if they aren't too expensive I can look into it
@matteoo3923
@matteoo3923 3 роки тому
Really interesting and well done guide. Can you share a MicroPython version too of the same tutorial?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
There is one in the works!
@jcc4tube
@jcc4tube 3 роки тому
Does micropython on the pico support non blocking read/write functions? Maybe using DMA?
@taranagnew436
@taranagnew436 2 роки тому
can you make a video about bit math and addresses?
@Morkiller
@Morkiller 3 роки тому
Wow, crystal clear explanation, thanks for that content. One quick question, do you know if there's any chance to print through the micro-usb port from the raspberry pi pico?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Glad you found the video helpful and clear! Yes you can print from the micro USB port over usb serial via the printf function (if I am understanding your question correctly). I have a video about USB serial on my channel which covers this.
@Morkiller
@Morkiller 3 роки тому
@@LearnEmbeddedSystems no hahaha, I was talking about printing on a real printer, like actually printing on a paper, printing on a paper.
@nextlifeonearth
@nextlifeonearth 3 роки тому
@@Morkiller you're probably going to want to use a normal raspberry pi for that. Like one with an operating system.
@raphaelkrauthann3981
@raphaelkrauthann3981 Рік тому
At 13:38 I am very confused about the data you are writing to the i2c. According to the specification, wouldn't this trigger a reset (0x40), and your next command trigger a self-test (0x01). Maybe you could clarify it for me, I am relatively new to this topic.
@mandyodd
@mandyodd 9 місяців тому
Please let me know can you connect i2c device on pico debug port.
@y2ksw1
@y2ksw1 3 роки тому
Could you consider to explain how the data IO works, for example by using 2 Pico's, one a host and one a client, or on itself. I am still confused about the bit order. Thanks!
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
I can look into this and I might make a video regarding communication between two Picos. Thank you for your suggestion
@y2ksw1
@y2ksw1 3 роки тому
@@LearnEmbeddedSystems Thanks! 👍
@SuperMasteroff
@SuperMasteroff 2 роки тому
Traceback (most recent call last): File "", line 7, in IndexError: list index out of range please help
@eFeXuy
@eFeXuy 3 роки тому
Can you make a video on how to debug the Pico via the SWD port?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
I am having problems myself trying to debug the Pico directly from a PC. It is currently working fine using another Pico but not directly to a PC. When I solve this, I will be sure to make a video covering this. Thank you for your suggestion!
@Chinesejacklee
@Chinesejacklee 25 днів тому
A question, at 13:01 mins, where is data[1]=0x40 from? Is 00100000 converted to 20 in hex? Should it be =0x20?
@jameslewis7620
@jameslewis7620 Рік тому
Where can I buy a breadboard like yours?
@robn2497
@robn2497 10 місяців тому
10:26 regarding the code: reg, then read then write functions: I need some clarity please: Is this correct idea??? The write function points at register 0x00 holds the bus using "true", so when the read function executes its looking at reg 0x00. These functions are confusing: there is physical connection point to pico: i2c0, device address 0x28 in your case, then a buffer to store the read information: In my head it should be: i2c0, device address, register (we want to read), buffer (to store the read), ect. How do I point at the registers since read and write only have device, data or device, buffer???
@cstanford8046
@cstanford8046 Місяць тому
Is the SCL really running at 400kHz? I doubt it. How about showing it on a logic analyzer?
@jyvben1520
@jyvben1520 3 роки тому
keep the micropython uf2 close, could be useful to check if the i2c device is properly connected, only needs a few lines of code to scan the i2c bus, can be done in the repl ... i expect . bus 1, pin 2 sda/3 scl (board pin 4+5) or bus 0, pin 8 sda, 9 scl (board pin 11+12), or any other duo as seen on Raspberry-Pi-Pico-Pinout-Diagram.jpg
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Great idea! Let us know when you have worked out which pins to use
@jyvben1520
@jyvben1520 3 роки тому
@@LearnEmbeddedSystems still waiting for the hardware, working with the pyboard-d for the moment
@jamesgardiner7196
@jamesgardiner7196 3 роки тому
It would be interesting to see this basic code turned into a library with a cpp and .h file
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Which part are you referring too, the general i2c communication or the BNO005 functions? I will have a look into putting the I2C code into a simple library but I am sure someone will have beaten me to it!
@jamesgardiner7196
@jamesgardiner7196 3 роки тому
@@LearnEmbeddedSystems i2c (or spi) communications into a library using VS code and Pico
@JuddMan03
@JuddMan03 Рік тому
Does this mean you cant use two I2C devices with the same address?
@carsonlaudadio7464
@carsonlaudadio7464 11 днів тому
Does anyone Haha e the issue ‘module ‘board’ has no module I2C’ ? I am running a Pi 4, and using Python. Strangely enough the exact same file works on my other Pi.
@edwardarruda7215
@edwardarruda7215 3 роки тому
Can you plot via .csv?
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
Yes this is completely possible, and fairly simple to do! If you are using PuTTY you can use the logging function to directly save the output as a CSV. This tutorial is for an arduino but is practically the same for the Pico: www.circuitbasics.com/logging-arduino-data-to-files-on-a-computer/
@VasaMusic438
@VasaMusic438 3 роки тому
what about MIDI by USB ??
@LearnEmbeddedSystems
@LearnEmbeddedSystems 3 роки тому
I have no personal experience using MIDI on the Pico, if I end up looking into it, I might make a video regarding this. Thank you for the suggestion
@Mr.Leeroy
@Mr.Leeroy 3 роки тому
2:03 that's some messed up level translator
@user-um3ui1gu9t
@user-um3ui1gu9t 2 роки тому
Every C compiler knows about binary representation !
I2C | Raspberry Pi Pico Workshop: Chapter 4.4
14:15
Core Electronics
Переглядів 760
Turning a Raspberry Pi Pico into a GPU!
16:42
element14 presents
Переглядів 98 тис.
3D printed Candy can AM SW FM crystal radio
26:16
BillyCdiy
Переглядів 189
The Pi Pico has problems, so I made my own, the ProPico
7:17
Dmytro Engineering
Переглядів 33 тис.
PlatformIO: All you need to know in 10 Minutes!
10:56
J's e-shack
Переглядів 277 тис.
Hacker's Guide to UART Root Shells
17:40
Flashback Team
Переглядів 448 тис.
Use BOTH Cores  |  Dual Core Programming on the Raspberry Pi Pico
7:49
Low Level Learning
Переглядів 37 тис.
Raspberry Pi Pico: 10 Things You Might Not Know
4:50
Ryan Gaudion
Переглядів 93 тис.
#370 Raspberry Pi Pico vs ESP32 (-S2) and STM32 Blackpill
15:53
Andreas Spiess
Переглядів 382 тис.
Using the Raspberry Pi Pico, PCA9685 and MicroPython for Robotics
1:10:35
Kevin McAleer
Переглядів 11 тис.