Search this site
Embedded Files

Home

PC - Pico Master Slave

I was disappointed when I discovered that I2C Slave was not implemented on the Pico Micropython. I have a nice project set up with 4 Arduinos doing I2C slave with an ESP 8266 as master and wanted to add a Pico and Seeduino XIAO to create a multi-processor lighthouse in a desert i.e. brilliant but useless! The XIAO was programmed in the Arduino IDE and works great.

I then went off on a tangent and decided to use the Pico as a slave on the USB serial port with the PC in the master role written in Python. The master builds commands and sends them to the Pico. The Pico has a command interpreter. The commands currently implemented do read and write on digital and analogue. In addition I have a flash routine that outputs a square wave without locking up the processor. I then attempted to use the second core of the Pico to handle the serial but I ran into all sorts of issues with the REPL locking up. It seems threading is still quite buggy. Instead I use a 1 millisecond timer interrupt to update the flash tasks that are running. This is version 0.9 of the code and has not been tested thoroughly. I’m just putting it up here for critical analysis and maybe some people will find parts of it useful.


Pico slave code

PC master code

The demo in the code above sets up 4 flash tasks each with their own On-Off times. Once started on the Pico these flash routines keep going being updated by the 1 millisecond timer interrupt. The PC starts sending commands to the Pico causing the end LED to ramp up and down under PWM control. In the loop the PC also requests the Pico chip temperature and modifies the ramping speed to run faster when the processor temperature rises a little. My finger on the chip raises the temperature. The ESP8266 is wired on to the board and initial experiments shows that it can send commands to the Pico using a slightly modified version of the PC code and some tweaks on the Pico code. I have a bit of work to do on this yet.

20210605_091916.mp4

This is my lighthouse in a desert. It provides a multiprocessor microcontroller board where each one runs independently and is centrally controlled by the ESP8266. Now how brilliant is that?? There are 4 Arduinos under the stripboard. This board carries the ESP8266. I use I2C between ESP (on Micropython) and the 4 Arduinos. The I/Os are all brought to headers. 8 uncommitted LEDS are available on the left and 4 switches on the right. I used EasyEDA to design the PCB. Each of the Arduinos run the same program and at the start they set their own I2C slave address based on the value of one of their analogue pins that are preset by a resistor chain. Can't think of a use for it yet.

Overall this Pc - Pico Mater Slave project was quite troublesome and frustrating as I had to work on two programs simultaneously running one on the Pico and the other on the laptop and using Teraterm to monitor output from the Pico. The ground was littered with hair. I use Notepad++ as my editor with a NPPExec script saving the file, calling mpy-cross, disconnecting TeraTerm to free up the port, calling ampy to transfer the file and finally reconnecting Teraterm. It works 95% of the time!

Email me your comments

Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse