Pico W - Bluetooth Communication
by tonygo2 in Circuits > Microcontrollers
8588 Views, 8 Favorites, 0 Comments
Pico W - Bluetooth Communication
In this Instructable I am going to demonstrate how to send live, dynamic data from one Pico W to another using the built-in Bluetooth (BLE) modules. I will read RGB colour data from three potentiometers connected to the first Pico W and display the data on a a NeoPixel strip connected to the second Pico W. The data will be passed between the two Pico Ws wirelessly using the Bluetooth Low Energy system using MicroPython code. Not only will you be able to display the Colours of the Rainbow but a range of 16,777,216 colours from jet black to brilliant white!
Supplies
- 2 x Pico W
- 2 x Breadboards
- 3 x 10K Ohm potentiometers
- 1x NeoPixel stick (Adafruit - 8 NeoPixels)
- Connecting wire
- Thonny editor installed on your computer (Free)
(All these components are widely available but I got mine from thepihut.com in the UK.)
Introduction
The documentation and example code for using Bluetooth with MicroPython have only recently been published. I'm going to modify one of the example programs to send live data rather than a the results of simple counts.
This project is for advanced users of MicroPython on the Raspberry Pi Pico so I will make a few assumptions about your current skills:
- You can set up two instances of Thonny on your computer
- You can update the UF2 file on your Pico W
- You can connect three 10K ohm potentiometers to the ADC pins on your Pico W
- You can connect a NeoPixel strip to GP15 on your Pico W
- You can copy a section of code from a Github address and save it as a file on both your Pico W and your file system.
Getting Started
The latest version of the Pico W UF2 is currently version 1.20.0 and it contains the Bluetooth libraries essential for this Instructable. Please update both of your Pico Ws to this version, or later. You can find the file here:
https://micropython.org/download/rp2-pico-w/
Documentation and Examples
The manufacturers of the Pico W have recently published a MicroPython guide to using Bluetooth on the Pico W and you can download it from here:
https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf
This provides a good introduction to Bluetooth on the Pico W and I suggest you start at Chapter 4. About Bluetooth on page 28 and follow on to the MicroPython section.
You can find the official examples and helper library can be found here:
https://github.com/micropython/micropython/tree/master/examples/bluetooth
We will need ble_advertising.py so download the code and save it on your system and both of your Pico Ws.
We will be using modified versions of the ble_simple_central.py and ble_simple_peripheral.py programs so you might want to download them and try them out. They demonstrate sending a count back and forth between the two Pico Ws.
Build Your Circuits
Connect the three 10K ohm potentiometers to GP26, GP27 and GP28 (ADC0, ADC1 & ADC2) and test your connections.
Connect the NeoPixel strip to GP15 on the other Pico W and test your connections
Download My Code
Download my code
There are two programs to download:
- POTs3 ble_simple_central.py to run on the Pico W with the potentiometers connected
- NeoPixel ble_simple peripheral.py to run on the Pico W with the Neopixel strip
Running the Project
Make sure that the two instances of Thonny have different connection ports and start the Neopixel/peripheral Pico, first and then the other one. The first one starts advertising its presence. As soon to the other Pico W finds it and connects the advertising stops and the values from the potentiometers is sent wirelessly to the to the Pico W which adjusts the colours shown on the strip. If the connection is broken the peripheral returns to advertising.
Now you have it working your can experiment by turning the potentiometers to make the Colours of the Rainbow. Red, Green and Blue are easy, Yellow,(Cyan,) and Purple are pretty simple, Orange a little harder with Indigo and Violet more difficult. I found making a Brown colour very difficult - give it a go!
Conclusion
I found that the system was pretty fast and very reliable, as you can see from the video.
I hope you have found this Instructable useful.
Have fun with your coding.