I've used the Picon Zero board from 4Tronix before when I was working on the Dragon Detector project. It is the same size as the Pi Zero and can drive 6 outputs, 4 inputs and 2 motors via H-Bridges. So it seemed a good option for driving my latest car project.
Prepare the Pi
The Picon Zero runs via I2C so you need to run raspi-config and enable I2C in the settings.
It's also worth updating the apt-get cache as we'll be installing some software.
sudo apt-get update
Install tools
This step is optional but it's good to have some tools for diagnosing what's going on.
sudo apt-get install i2ctools
This then allows you to see what I2C adapters are available. This will be different on early pi but most modern Pi are have the I2C bus numbered as "1"
sudo i2cdetect -l
That will return something like:
i2c-1 i2c bcm2835 I2C adapter I2C adapter
Then the scan command will detect if the board is plugged in and can be detected.
sudo i2cdetect -r 1
It will return something like the following:
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-1 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] Y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- 22 -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Install software
First I removed any existing versions of node and npm (the node package manager)
sudo apt-get remove --purge npm node nodejs
Then I used an excellent script from Steven de Salas to install the latest version of node.
wget -O - https://raw.githubusercontent.com/sdesalas/node-pi-zero/master/install-node-v.last.sh | bash
After checking the versions I installed an I2c libraries so that Node could communicate with the I2C bus
node -v npm -v npm install i2c
Porting the Picon Zero code to Node
I tried out the "jiphy" tool to see if I could automate some of the code migration. That seemed to work ok with the smaller samples but it choked on the main library. So I ended up porting the code by hand. So far I've just done the version funtion as that allows me to see that communication is happening. I've also tried to mimic the Python version so that people can easily work with either. Here's the two versions side by side.
Python | NodeJS |
---|---|
#! /usr/bin/env python # GNU GPL V3 # Test code for 4tronix Picon Zero import piconzero as pz pz.init() vsn = pz.getRevision() if (vsn[1] == 2): print("Board Type:", "Picon Zero") else: print("Board Type:", vsn[1]) print("Firmware version:", vsn[0]) print() pz.cleanup() | #!/usr/bin/env node // GNU GPL V3 // Test code for 4tronix Picon Zero var pz = require('./piconzero'); pz.init(); var vsn = pz.getRevision(); if (vsn[1] == 2) { console.log("Board Type:", "Picon Zero") } else { console.log("Board Type:", vsn[1]) } console.log("Firmware version:", vsn[0]) console.log(); pz.cleanup(); |
So far it's a proof of concept but it seems to be working reliably so I can't see any problems with porting the rest.
Watch this space https://github.com/Workshopshed/PiconZero/tree/master/NodeJS
Reference
https://blog.miniarray.com/installing-node-js-on-a-raspberry-pi-zero-21a1522db2bb
https://github.com/sdesalas/node-pi-zero
https://github.com/timothycrosley/jiphy/blob/develop/README.md
Top Comments