gareth – layer zero labs https://l0l.org.uk.archived.website make it, break it, fix it, hack it, own it Sun, 24 May 2015 10:29:59 +0000 en-GB hourly 1 https://wordpress.org/?v=4.5.14 Headaches whilst upgrading to Raspberry Pi 2 https://l0l.org.uk.archived.website/2015/02/headaches-whilst-upgrading-to-raspberry-pi-2/ https://l0l.org.uk.archived.website/2015/02/headaches-whilst-upgrading-to-raspberry-pi-2/#comments Wed, 18 Feb 2015 13:39:16 +0000 https://l0l.org.uk.archived.website/?p=706 So we’ve been having difficulty getting the underwater fish cam streaming reliably – and now that there is a higher-powered Pi around I thought that I’d try upgrading the basestation of our Aquaponics control system to see if the extra ooomph helps. But of course, there are new problems – such as our old way of […]

The post Headaches whilst upgrading to Raspberry Pi 2 appeared first on layer zero labs.

]]>
So we’ve been having difficulty getting the underwater fish cam streaming reliably – and now that there is a higher-powered Pi around I thought that I’d try upgrading the basestation of our Aquaponics control system to see if the extra ooomph helps.

But of course, there are new problems – such as our old way of getting kernel headers doesn’t seem to work. Why the foundation have rolled their own kernel and then made it so hard for people to get kernel headers is beyond me, surely they want people to hack on the thing??!! If anyone can explain this please leave a comment – it seems like an obvious gaff, and a longstanding one too. The Pi forums are full of people struggling with this, as they have been since 2012! I just don’t get why they have done this, it makes my life harder and what does it accomplish? Grrrrrr…

Anyway, I’ve been searching and experimenting and I think I’ve got a new way to get the headers, so that we can compile the drivers for various things such as the rfm12b driver. It’s as simple as adding ‘2’ to the install of linux-image-rpi-rpfv and linux-headers-rpi-rpfv to make them linux-image-rpi2-rpfv and linux-headers-rpi2-rpfv.

Also, the new device-tree may cause issues – using the raspi-config utility handles this automagically – see here for an excellent explanation of the issue.

The post Headaches whilst upgrading to Raspberry Pi 2 appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2015/02/headaches-whilst-upgrading-to-raspberry-pi-2/feed/ 3
ESP8266 modules hardware guide – gotta catch ’em all! https://l0l.org.uk.archived.website/2014/12/esp8266-modules-hardware-guide-gotta-catch-em-all/ https://l0l.org.uk.archived.website/2014/12/esp8266-modules-hardware-guide-gotta-catch-em-all/#comments Fri, 05 Dec 2014 13:46:31 +0000 https://l0l.org.uk.archived.website/?p=618 OK so there is this new(ish) chip the ESP8266EX that promises a full wifi stack and a mcu all for £2-3. But the chip on it’s own isn’t so useful – so most of the excitement has been around the various modules made with the chip, some memory and an antenna or connector for one. […]

The post ESP8266 modules hardware guide – gotta catch ’em all! appeared first on layer zero labs.

]]>
OK so there is this new(ish) chip the ESP8266EX that promises a full wifi stack and a mcu all for £2-3. But the chip on it’s own isn’t so useful – so most of the excitement has been around the various modules made with the chip, some memory and an antenna or connector for one. Unfortunately there is a lot of diversity, modules being revised and so on – which makes choosing one of these modules quite difficult. Here I’ve tried to bring together all the info I could about these different modules to help you choose which one fits your needs best. If you have any information about these modules then please leave a comment and I’ll incorporate it! The modules have attracted the codes ESP-01 through ESP-12 – this document in Chinese and this webshop catalog formed the starting point. The ESP8266.com community and Squonk, shekel, TuxFanGKR and others deserve credit for gathering most of this infomation here.

espfront
front of ESP modules ESP-01 through ESP-11
espback
back of ESP modules ESP-01 through ESP-11

The basic attributes of these modules are as follows:

Modules

Dimensions

Picture

Pinout

Antenna

GPIO

Notes

ESP-01 14.3mmx24.8mm ESP 01 Module photo variant 1 ESP-01 Modules pinout variant 1 PCB Antenna GPIO0/2/16 Multiple Variants Exist! Most common module. This version may be known as V090 or V091
ESP-02 14.2mmx14.7mm ESP-02 Module photo variant 1 ESP-02 Modules pinout variant 1 U-FL connector GPIO0/2/15 Multiple Variants Exist!
ESP-03 17.4mmx12.2mm ESP-03 Module photo ESP-03 Module pinout Ceramic Antenna GPIO0/2/12/13/14/15/16 Most popular in esp8266.com poll
ESP-04 14.7mmx12.1mm ESP-04 Module photo ESP-04 Modules pinout none GPIO0/2/12/13/14/15/16
ESP-05 14.2mmx14.2mm ESP-05 Module photo variant 1 ESP-05 Modules pinout variant 1 U-FL connector NONE Multiple Variants Exist!
ESP-06 14.2mmx14.7mm ESP-06 Module photo ESP-06 Modules pinout None GPIO0/2/12/13/14/15/16 Metal shield claims FCC
ESP-07 22mmx16mm ESP-07 Module photo ESP-07 Modules pinout Ceramic Antenna & U-FL connector GPIO0/2/4/5/12/13/14/15/16 Multiple Variants Exist! Metal shield claims FCC
ESP-08 17mmx16mm ESP-08 Module photo ESP-08 Modules pinout None GPIO0/2/12/13/14/15/16 Metal shield claims FCC
ESP-09 10mmx10mm ESP-09 Module photo ESP-09 Modules pinout None GPIO0/2/12/13/14/15 1MB Flash memory
ESP-10 14.2mmx10mm ESP-10 Module photo ESP-10 Modules pinout None None
ESP-11 19.3mmx13mm ESP-11 Module photo ESP-11 Modules correct pinout Ceramic Antenna GPIO0/1
ESP-12 24mmx16mm ESP-12 Module photo ESP-12 Modules pinout PCB Antenna ADC + GPIO0/2/4/5/12/13/14/15/16 Metal shield claims FCC
DWA8 17mmx27.1mm DWA 08 Module photo DWA 08 Module pinout PCB Antenna ADC + GPIO0/2/12/13/14/15/16

ESP-01 Variants:

Tinhead of the esp8266.com community contributed info about an older variant using the ESP8266 rather than ESP8266EX (may also be referred to as v080):

ESP-01 Module photo variant 2 frontESP-01 Module photo variant 2 backESP-01 Modules pinout variant 2

ESP-02 Variants:

TuxFanGKR of the esp8266.com community reported that a pinout variant had made him let the magic smoke out! And a third variant (confusingly named ESP-02 version 2) has been spotted here. Pinout is of TuxFanGKR’s variant – photo of ‘version 2’.

ESP-02 Modules pinout variant 2ESP 02 Module photo variant 3

ESP-05 Variants:

A fifth pin has been added to the ESP-05 module carrying reset, thanks to esp8266.com contributors gbit and Didier9 for this info:

ESP 05 Module photo variant 2ESP-05 Modules pinout variant 2

 

ESP-07 Variants:

A variant of the ESP-07 has been reported with 2 extra connections (one of them ADC) by mvdlande on the esp8266.com forum:

ESP 07 Module photo variant 2

References:
ESP8266EX Pinout
Hardware guide

Any corrections, omissions or improvements? Please leave a comment!
Thanks to comment below, pinout of module ESP-11 has been corrected.

The post ESP8266 modules hardware guide – gotta catch ’em all! appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/12/esp8266-modules-hardware-guide-gotta-catch-em-all/feed/ 45
thethingbox.io image – testing and extending https://l0l.org.uk.archived.website/2014/08/thethingbox-io-image-testing-extending/ https://l0l.org.uk.archived.website/2014/08/thethingbox-io-image-testing-extending/#respond Tue, 26 Aug 2014 08:13:23 +0000 https://l0l.org.uk.archived.website/?p=564 I’ve started investigating the http://thethingbox.io/ image – they say ‘Just download and write a Raspberry-Pi binary file on a SD card to get it ready!’ Well, that’s mostly true – but I found a few issues once I logged on to it via ssh that I’ve documented here, mostly easy to fix once you know how. […]

The post thethingbox.io image – testing and extending appeared first on layer zero labs.

]]>
I’ve started investigating the http://thethingbox.io/ image – they say ‘Just download and write a Raspberry-Pi binary file on a SD card to get it ready!’ Well, that’s mostly true – but I found a few issues once I logged on to it via ssh that I’ve documented here, mostly easy to fix once you know how.

So after booting from the card, I ssh’d into it – as root with a password of ‘raspberry’. I change this immediately:
passwd

set the locale, timezone and keyboard:
dpkg-reconfigure locales
echo 'Europe/London'>/etc/timezone && dpkg-reconfigure -f noninteractice tzdata
dpkg-reconfigure console-data

Now some updates:
rpi-update
aptitude update
aptitude upgrade -y
aptitude install sudo

Follow the code in the first post here: http://www.raspberrypi.org/forums/viewtopic.php?f=28&t=64843 for a recent copy of fsck.vfat to fix the errors on the boot partition.

I prefer to work as a normal user so I’ll create one
adduser pi

Answering various questions about the new user pi got me a home directory, then on to joining a few extra groups (not sure if all are needed, tbh!):
usermod -a -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev pi

Finally change the hostname to ‘whateveryoucallyoursystem’ by changing the hostname and /etc/hosts files:
echo '127.0.1.1 whateveryoucallyoursystem'>>/etc/hosts
echo 'whateveryoucallyoursystem'>/etc/hostname

and reboot.

Now we can log in as normal user pi!

The post thethingbox.io image – testing and extending appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/08/thethingbox-io-image-testing-extending/feed/ 0
Open aquaponics API, documented with Swagger and sample app https://l0l.org.uk.archived.website/2014/08/open-data-api-documented-swagger-sample-app-github-natch/ https://l0l.org.uk.archived.website/2014/08/open-data-api-documented-swagger-sample-app-github-natch/#respond Thu, 07 Aug 2014 17:11:54 +0000 https://l0l.org.uk.archived.website/?p=539 We’re proud to release the first public iteration of our Aquaponics Open Data API. You can see it live here – and we are very keen to get feedback, suggestions, improvements and collaborators in true open-source fashion. Our goal is to allow others to write applications to use data from our systems for their own purposes, as well as reusing […]

The post Open aquaponics API, documented with Swagger and sample app appeared first on layer zero labs.

]]>
We’re proud to release the first public iteration of our Aquaponics Open Data API. You can see it live here – and we are very keen to get feedback, suggestions, improvements and collaborators in true open-source fashion.

Aquaponics API
Swagger documentation of our Aquaponics API

Our goal is to allow others to write applications to use data from our systems for their own purposes, as well as reusing our API and apps themselves. The API is documented using the fabulous Swagger specification – we used the swagger-node-express because we like node. Swagger provides great looking documentation of the API as well as full details of the responses and error codes, but wait – there’s more. It’s not documentation in the usual sense, it’s an interface to the API itself. Thus it provides a really easy way to test the API out and get real data back, complete with headers and response codes – everything you need to develop apps against it.

Our system uses the seriously hard-core Cassandra database – even though we can’t quite justify it based on our data-needs today! In fact when we asked a support question on the Cassandra IRC channel we were told that a mere two box cluster was ‘not a typical deployment’! But it fits our requirements in terms of storing time-series data – and we have great hopes that soon we’ll be needing racks of boxes across several continents. If it’s good enough for GitHub and CERN then it’s good enough for us.

Speaking of GitHub, all our code are belong to you – this means it’s released under the GPL v2 and you’re welcome (and obligated!) to use it, abuse it, improve it and then return those improvements back to the common pot.

As well as all of this, we’ve also written an app that uses our API to present a simple web form allowing for the download of data in csv format. You can try out our download app here – again we really do appreciate your feedback (it’s the best way to get better).

Download as CSV web app
Download aquaponics data as CSV

Node express allowed us to get this simple web-app up and running with the minimum of fuss and maximum of effect. We’re hoping to follow this up with a graphing app very soon – watch this space.

We’ll be showcasing the system and its associated API , apps and dashboard at the very wonderful Wuthering Bytes open hardware festival in Hebden Bridge – if you can possible be there – you must! As well as our talk/workshop there are dozens of great things happening from Sophie Wilson to space rocket launches and beyond!

The post Open aquaponics API, documented with Swagger and sample app appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/08/open-data-api-documented-swagger-sample-app-github-natch/feed/ 0
Wireless pH sensor https://l0l.org.uk.archived.website/2014/05/wireless-ph-sensor/ https://l0l.org.uk.archived.website/2014/05/wireless-ph-sensor/#comments Thu, 22 May 2014 12:50:10 +0000 https://l0l.org.uk.archived.website/?p=515 JeeNode + MinipH + LiPo + Case = Wireless pH sensor This sensor is probably the one I’m most proud of so far, all the elements came together really well despite having to hack the MinipH circuit in the literal sense! The enclosure maketh the project As soon as I had finished making this sensor, […]

The post Wireless pH sensor appeared first on layer zero labs.

]]>
JeeNode + MinipH + LiPo + Case = Wireless pH sensor
wireless pH sensor
wireless pH sensor

This sensor is probably the one I’m most proud of so far, all the elements came together really well despite having to hack the MinipH circuit in the literal sense!

The enclosure maketh the project

As soon as I had finished making this sensor, and put the lid on and stepped back, I was genuinely surprised and pleased with how much better the sensor suddenly seemed. Despite the fact that I knew exactly how much sweat and tears had been expended and all the clever details, even then, I was mostly impressed when the case went together!!

At first I was a bit disconcerted by this, I am constantly trying to see the ‘real substance’ of things, ideas and people, rather than just see the ‘surface’ details. And yet, even with a project of my own that I knew intimately, I was beguiled by the case.

So anyway, the case turned out to be the perfect size, the quality of the plastic (ABS) and surface finish is very good, the sides feel strong and mate well with each other. It’s made by Evatron, model PC001 and I ordered a black and white one, both with and without a battery compartment from CPC in the UK (£4.54 with free delivery).

I prefer the look of the white one, its not trying to be Apple white (they’ve probably patented that one) but it’s not beige either – I suppose ivory is a fair description. The battery compartment option tempted me but I decided in the end that it would never be moisture or splash-proof let alone waterproof with a door.

Construction details

Inside the pH sensor
Inside the pH sensor

One of the first and easiest decisions was to remove some of the little plastic mounts intended for internal pcbs, they just get in the way. I snipped most of them off with heavy duty wire cutters and then used a sharp chisel to cut the remains of the plastic flush to the surface. Then the hole can be made in the middle of an end, it needs to be 12mm to accomodate the BNC connector of the pH pH probe circuit. I find that it’s very difficult to drill holes accurately without a pillar drill, especially in this sort of situation where the hole needs to go in the middle of where the case splits. However, it is perfectly possible to mark out pretty accurately by careful measurement and ‘eyeing’ up the marks from several angles. So I just marked out the hole as carefully as I could, then drilled it roughly in the middle at 10mm. I then used a file to remove the rest of the material and return the hole to a centred circle. I tried to retain a flat on one side of the hole, to match the mounting pattern of the connector, but it’s not vital.

Now in order to fit the pH sensor circuit we need to hack it – this time with a fine hacksaw. I spend quite a few minutes examining the board layout files (yet another reason to love open source hardware!) and a load more time examining the physical circuit, and became convinced that there weren’t any traces or components that I’d be damaging. The physical construction of this type of circuit is important, but I reassured myself that I wouldn’t be breaking any guard traces, just clipping off a bit of ground plane.

MinipH circuit cut to fit case
MinipH circuit cut but unblodied

Needless to say, despite my brave words I was more than a bit apprehensive to take a hacksaw to such a perfectly formed little board. Perhaps this is what novice surgeons feel the first few times they have to cut into somebody? Anyway the operation was a success, and the patient was able to make a full recovery, minus a corner.

The MinipH circuit is from Sparky’s Widgets – aka Ryan Edwards – another hacker hero of mine! (I think I’m going to have to make a page of them soon). He has some great info on his site that really helped me understand some of the more subtle aspects of pH measurement.

I decided to use the hardware I2C port rather than the software ports provided as part of JeeLib – I figured that perhaps the processing overhead might be a bit lower, but I haven’t tested that assumption. The demo sketch provided with the hardware worked great out of the box, and Naomi then wrapped it in a class and got the data sent over the radio.

The only other fiddly detail was getting the power consumption down, as the circuit consumes a few milliamps constantly. I tried a few different ways to power the circuit and eventually settled on using a digital out to raise vcc high when I need it. The draw of the circuit is well inside the limits for the IO pins, and it seems to work fine. This way I can sleep most of the time and only switch on the sensing circuit when required.

I did some testing and found that the pH circuit needs quite a bit of time to settle, and I ended up allowing five seconds for the circuit to ‘warm up’ before reading from it. Even then the results often carry on dribbling up (or down) for quite a while. So rather than a pattern of ‘wake up, measure, sleep’ that we’re currently using, in the future we’ll be implementing a scheme where the sensor wakes up, keeps the pH circuit powered up for some time whilst taking measurements, then sleeps. Of course the mcu/radio can be sleeping during most of the measurement time, but the sensor would remain powered up.

In an ideal world I’d like to do some more clever work in software to measure the speed of change and basically predict where the results will settle. This should give a fast reading despite the pH probe actually taking ages to settle. And also, let’s face it, getting pH accurate to one decimal place is great for most situations, and the extra place may be questionable anyway as I’m not sure the accuracy is quite equal to the resolution.

And finally, the battery is from Adafruit, as detailed in the overview page. With a sleep current of 7μA against a capacity of 1200mAh, we should be good for a couple of years I reckon, even if we spend a fair fraction of one percent of the time awake.

The microcontroller sketches that configure and then run the sensor are available over at github – we are developing a system based on Node-RED to receive the data that you can also download from github. I hope that you find our work useful, and build something yourself with it, just as we’ve built on the astounding work of so many others. Happy hacking!!

The post Wireless pH sensor appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/05/wireless-ph-sensor/feed/ 7
Node-Red on Raspberry Pi with RFM12B support https://l0l.org.uk.archived.website/2014/05/commands-get-node-red-controller-raspberry-pi-rfm12b-support/ https://l0l.org.uk.archived.website/2014/05/commands-get-node-red-controller-raspberry-pi-rfm12b-support/#comments Mon, 19 May 2014 16:54:17 +0000 https://l0l.org.uk.archived.website/?p=424 You can find these rfm12b modules on sale on ebay – I paid about £10 with delivery and it arrived promptly, the seller chacal_zoom seems to have a number of interesting little circuits, specialising in minimum parts and tiny boards! (avoid the bedini circuit tho he he he!!!) After seemingly endless weird problems getting the […]

The post Node-Red on Raspberry Pi with RFM12B support appeared first on layer zero labs.

]]>
Raspberry Pi with rfm12b radio
Raspberry Pi with rfm12b radio

You can find these rfm12b modules on sale on ebay – I paid about £10 with delivery and it arrived promptly, the seller chacal_zoom seems to have a number of interesting little circuits, specialising in minimum parts and tiny boards! (avoid the bedini circuit tho he he he!!!)

After seemingly endless weird problems getting the rfmb12 driver working and loaded automatically as well as re-installs, imaging mishaps etc. I’m now getting both more expert at configuring raspian and somewhat bored. Also I’m now convinced that we’ll always be going wireless from now on, so the rfm12b driver is a must. Plus Wiring-Pi and a couple of other nodes added into node-red for completeness, giving a ‘base-system’ setup.

So I’ve decided to go scriptomatic and as a first step I’ll list some commands that you can just paste into the terminal and go away and have a light meal while stuff installs. At the moment you will have to come back after the starter because there is a reboot early on to start using the new kernel.

So, having created an SD card with raspian on it I expand the file-system now rather than later, to make sure I leave a couple of hundred MB for SD block failures. On boot, login with the default username of pi and password raspberry. Run sudo raspi-config to enter the easy config. Change password and then in advanced – change hostname, ensure that the graphics split is 16MB, enable SPI and reboot.
Now you can log back in with your new password and then paste the commands below.

EDIT – NOT YET WORKING ON PI 2!! But you can install headers by replacing the ‘rpi’ with ‘rpi2’ if you are using a Raspberry Pi 2 – and either way don’t forget to update the version numbers in my example e.g. “3.12-1-rpi” with the ones you actually downloaded in /boot – e.g. “3.18.0-trunk-rpi2”.

1st – Kernel with headers – 8 min

echo 'Europe/London' | sudo tee /etc/timezone
sudo dpkg-reconfigure -f noninteractice tzdata
sudo aptitude update
sudo aptitude install -y linux-image-rpi-rpfv linux-headers-rpi-rpfv
echo -e "kernel=vmlinuz-3.12-1-rpi\ninitramfs initrd.img-3.12-1-rpi followkernel" | sudo tee -a /boot/config.txt
sudo reboot

The next set of commands do some config as well as installation of the radio driver, so edit them if you want a different node id by default for example.

2nd – RFM12b driver installation – 1 min

git clone https://github.com/gkaindl/rfm12b-linux.git
cd rfm12b-linux
sed -i rfm12b_config.h -e 's/#define\ RFM12B_BOARD[[:space:]]*0/#define\ RFM12B_BOARD\ 1/g'
sed -i rfm12b_config.h -e 's/#define\ RFM12B_DEFAULT_GROUP_ID[[:space:]]*211/#define\ RFM12B_DEFAULT_GROUP_ID\ 101/g'
sed -i rfm12b_config.h -e 's/#define\ RFM12B_DEFAULT_JEE_ID[[:space:]]*0/#define\ RFM12B_DEFAULT_JEE_ID\ 1/g'
make
sudo cp rfm12b.ko /lib/modules/$(uname -r)/
echo -e "rfm12b" | sudo tee -a /etc/modules
sudo depmod -a
cd examples
make
cd ~

Edit – if you have errors at the make stage then recently I found that there was a test at line 25 of the Makefile that was erroring – as we are past version 3.7 we can remove the test and just always execute the line after it. So delete line 25 from the Makefile – it starts with if [ -f /lib/….

Now to prepare for the big update/install of everything else we install Gordon’s excellent Wiring-pi library.

3rd – Installing wiring-pi – 1 min

git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd ~

And finally, for something completely different. Some more installation stuff, this time you shouldn’t rush back …

4th – Main update & installation of packages ~ 30 min

sudo aptitude upgrade -y
sudo aptitude install bootlogd mosquitto
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
rm node_latest_armhf.deb
sudo adduser --system node-red --ingroup pi
sudo chmod 775 /home/node-red
cd /home/node-red
npm install node-red
cd node_modules/node-red
npm install serialport stately wiring-pi

And just add in the startup script from here, edit the init script to use the node-red user and you’re golden.
sudo wget -O /tmp/download https://gist.github.com/Belphemur/cf91100f81f2b37b3e94/download && sudo tar -zxf /tmp/download --strip-components 1 -C /etc/init.d && sudo chmod +x /etc/init.d/node-red && sudo update-rc.d node-red defaults

The post Node-Red on Raspberry Pi with RFM12B support appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/05/commands-get-node-red-controller-raspberry-pi-rfm12b-support/feed/ 2
RFM12B linking a JeeNode Micro with a Raspberry Pi https://l0l.org.uk.archived.website/2013/11/rfm12b-linking-jeenode-micro-raspberry-pi/ https://l0l.org.uk.archived.website/2013/11/rfm12b-linking-jeenode-micro-raspberry-pi/#comments Sun, 24 Nov 2013 09:20:37 +0000 https://l0l.org.uk.archived.website/?p=219 I’m going to try to use my new RFM12B based JeeNode Micro from JeeLabs to talk to a Raspberry Pi equipped with another RFM12B. Although the radio module (and JeeNode) are from JeeLabs, I’m going to connect it to a raspberry pi using an Eve-alpha board I got via the Ciseco kickstarter a while back. […]

The post RFM12B linking a JeeNode Micro with a Raspberry Pi appeared first on layer zero labs.

]]>
I’m going to try to use my new RFM12B based JeeNode Micro from JeeLabs to talk to a Raspberry Pi equipped with another RFM12B. Although the radio module (and JeeNode) are from JeeLabs, I’m going to connect it to a raspberry pi using an Eve-alpha board I got via the Ciseco kickstarter a while back. The eve board just makes the connections, it doesn’t have any circuitry involved in the path.

Posts on the Eve-alpha wiki led me to an image of the modifications I needed to make:  Now I have the radio connected to CE1 to enable it and GPIO 24 (#5 in WiringPi convention) as the IRQ line. Potentially this could allow us to be polled when messages arrive. (Actually I needed to change this later on – stay tuned!)

I found a raspberry pi driver that exposes the RFM12B as a device in /dev/ Fantastic!! It’s here. So we can download it and then edit the config with a
git clone https://github.com/gkaindl/rfm12b-linux.git
cd rfm12b-linux
nano rfm12b_config.h

The following values needed to be changed for my situation, one to enable use with the raspberry pi and the other seemed like a good idea, as I’ll be planning to interoperate with JeeLib code shortly:

#define RFM12B_BOARD 1
#define RFM12B_DEFAULT_JEE_ID 1

Then make moaned about not having the kernel sources. So I installed the 3.10-3-rpi kernel (was 3.6) and rebooted as detailed here.

EDIT – responding to issues raised on Github – boiled down method of installing a recent kernel complete with headers on bare 2014-01-07-wheezy-raspbian is:
sudo aptitude update && sudo aptitude upgrade -y
sudo aptitude install -y linux-image-rpi-rpfv linux-headers-rpi-rpfv
echo -e "kernel=vmlinuz-3.10-3-rpi\ninitramfs initrd.img-3.10-3-rpi followkernel" | sudo tee -a /boot/config.txt

EDIT – Raspberry Pi 2 ISN’T WORKING YET! see here. 

On reboot, uname -r should say something like

3.10-3-rpi

rather than

3.10.25+

Now the code will compile! Back in the rfm12b directory, we can proceed to load the spi module (if not blacklisted in /etc/modprobe.d/raspi-blacklist.conf) and the radio driver:

sudo modprobe spi-bcm2708
sudo insmod rfm12b.ko

If this works you probably want it loaded on boot automagically like this

sudo cp rfm12b.ko /lib/modules/3.10-3-rpi/
echo -e "rfm12b" | sudo tee -a /etc/modules
sudo depmod -a

On the JeeNode Micro, code from JeeLabs seemed a good place to start, but I also need a way to get code onto the Jeenode micro. Unlike many larger arduino compatible/inspired devices, it doesn’t provide a USB interface. Instructions at JeeLabs suggested I could use the Arduino IDE, and a diagram.

The latest beta of Arduino is more friendly with other hardware, so I downloaded that with a
wget http://downloads.arduino.cc/arduino-1.5.4-linux32.tgz
tar xzf arduino-1.5.4-linux32.tgz

Next the hardware description of the JeeNode board from Jean Claude’s repository is needed, so I downloaded and extracted that:
git clone https://github.com/jcw/ide-hardware.git
mv ide-hardware arduino-1.5.4/hardware/jeelabs
.

Now when I start the arduino IDE I get an extra option in the board menu!!

The latest Arduino IDE with the addition of JeeLabs JeeNode Micro board.
The latest Arduino IDE with the addition of JeeLabs JeeNode Micro board.

Using my cheapy clone USBasp device (but ensuring that I didn’t connect the 5v to the JeeNode Micro) I managed to set the fuses:

avrdude -v -p t84 -c usbasp -U lfuse:w:0xc2:m -U hfuse:w:0xd7:m -U efuse:w:0xff:m

and then I could use the ‘Upload Using Programmer’ in the arduino IDE to program the JeeNode. I uploaded the rfm12b_echo_client example to the JeeNode and fixed it up so that the baud rate was one of the permitted ones for TinySerial (it only supports a few baud rates so setting it to other values supported by the regular serial library gives an error on compilation). I also added the lines from the JeeLabs site to turn the radio on just before the rfm_initialise command:

bitSet(DDRB, 0);
bitClear(PORTB, 0);

After a bit of faffing I was able to see the send LED pinging away every second, but nothing on the raspberry pi side where I was running rfm12b_jeenode and rfm12b_echo alternately. After many false starts I finally re-read the kernel driver instructions again and remembered that the interrupt line is specified as going to pin 22 on the pi’s GPIO, not the one I’d used following the Eve Alpha guide.

Once I soldered the wire to that line instead, the raspberry pi started echoing ‘hello’ from the radio! I moved all round the house and couldn’t get it to drop a packet, even from the kitchen to the bedroom (it’s not a big house, to be fair).

The post RFM12B linking a JeeNode Micro with a Raspberry Pi appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2013/11/rfm12b-linking-jeenode-micro-raspberry-pi/feed/ 13
Command line control of arduino using ino https://l0l.org.uk.archived.website/2013/11/command-line-control-arduino-using-ino/ https://l0l.org.uk.archived.website/2013/11/command-line-control-arduino-using-ino/#respond Tue, 19 Nov 2013 13:07:50 +0000 https://l0l.org.uk.archived.website/?p=202 As we’re going to be programming the arduino via the raspberry pi over ssh, we need a command line tool to talk to the arduino. Luckilly several such ways exist, including make-files from several sources. I chose to use a tool called ino which seems to have packaged up the toolchain in a fairly decent […]

The post Command line control of arduino using ino appeared first on layer zero labs.

]]>
As we’re going to be programming the arduino via the raspberry pi over ssh, we need a command line tool to talk to the arduino. Luckilly several such ways exist, including make-files from several sources. I chose to use a tool called ino which seems to have packaged up the toolchain in a fairly decent way.

I’ve just used this to connect to the pi in Todmorden and remotely upload a fresh copy of the firmware and reset the arduino! now it’s started talking mqtt again, and all from across the internet!

Installation was relatively straightforward – good guide here: http://www.recantha.co.uk/blog/?p=1103.

sudo aptitude update && sudo aptitude upgrade -y
sudo aptitude install arduino picocom python-pip
sudo easy_install configobj jinja2 ino

Then create a new directory for a sketch, enter it and initialise ino:
mkdir AquaSensors
cd AquaSensors
ino init

Then the source files can be copied across into the src directory, external libraries into the lib directory (still inside a directory for each library tho!) – then compile with:
ino build

If we want to copy a hex file rather than compile it locally, then it should be renamed as .build/boardname/firmware.hex so in our case .build/mega2560/firmware.hex

Either way, to take the hex file and to upload it:
ino upload
from within the sketch directory.

To set sketch based or global defaults for ino, such as serial port & speed or board type, you can create an ini file.

This can be put either in the sketch folder as ino.ini, or as /etc/ino.ini or as ~/.inorc. The latter option gives a default for the user, the /etc/ino.ini one is global across the system (all can be overridden by command line options at invocation.)

Our file is global across all users so the following was saved to /etc/ino.ini:

board-model = mega2560

The post Command line control of arduino using ino appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2013/11/command-line-control-arduino-using-ino/feed/ 0
Setting up a Pi from bare Raspbian to work as a Node-Red controller https://l0l.org.uk.archived.website/2013/11/setting-pi-bare-os-work-node-red-controller/ https://l0l.org.uk.archived.website/2013/11/setting-pi-bare-os-work-node-red-controller/#respond Fri, 15 Nov 2013 17:39:56 +0000 https://l0l.org.uk.archived.website/?p=179 Here is a set of instructions to go from bare Raspbian to work as a Node-Red controller and also send text (sms) alerts using a 3G usb dongle. For various reasons I’ve needed to retrace my steps a few times, so here I’ll document them all for my and your convenience. Starting point is a […]

The post Setting up a Pi from bare Raspbian to work as a Node-Red controller appeared first on layer zero labs.

]]>
Here is a set of instructions to go from bare Raspbian to work as a Node-Red controller and also send text (sms) alerts using a 3G usb dongle.

For various reasons I’ve needed to retrace my steps a few times, so here I’ll document them all for my and your convenience. Starting point is a fresh download of Raspian (2014-01-07). End point will be auto-running a monitoring node with sms capability.

My latest trick is to create a 200MB ‘dummy’ partition at the end of the SD card using gparted before putting the card in the pi. Because the auto-resize script can’t deal with this arrangement I also expand the partition in gparted. This way the main, expanded filesystem will be a little bit smaller, to cope with the fact that sometimes SD cards are a few MB smaller than you would like. Now I can image and recover the main two partitions and if the dummy partition gets corrupted because it is truncated then it can just be deleted.

After first boot, ssh using username pi and password raspberry. Run sudo raspi-config to enter the easy config. Change password and set the timezone, then in advanced – change hostname, ensure that the graphics split is 16MB, enable SPI and reboot.

Ok, now after logging back in we do a quick install of some packages via aptitude (also adding in mosquitto for mqtt brokering and gammu for text messaging):
sudo aptitude update && sudo aptitude upgrade -y
sudo aptitude install bootlogd monit mosquitto gammu gammu-smsd

Now get the node stuff: (not sure if the npm updates are needed or not tbh!)
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
rm node_latest_armhf.deb
sudo npm install node-red -g
cd /usr/local/lib/node_modules/node-red
sudo npm install serialport stately wiring-pi
sudo npm update

Configure gammu (from this excellent page, thanks Mattias!) by identifying the port. Plug in your 3G dongle with a valid, activated sim card. Use dmesg | grep ttyUSB to find the USB port used for the modem. I found that I had three ports assigned and I tried them all to find that the last one assigned worked. Gammu has a config script helper you can activate with a sudo gammu-config – the only thing I needed to change was the port. Then your should get a sane response from sudo gammu --identify like this:

Device : /dev/ttyUSB2
Manufacturer : Huawei
Model : unknown (K3520)
Firmware : 11.314.12.02.00
IMEI : 15 digit no.
SIM IMSI : 15 digit no.

Now we need to edit the gammu daemon config file with sudo nano /etc/gammu-smsdrc to put the port and speed used by the modem in, e.g. /dev/ttyUSB2 and at19200. To test it you can start the daemon with sudo service gammu-smsd start and then echo "Hello Earth, Mars calling" > /var/spool/gammu/outbox/OUT###########.txt (replacing the #’s with your phone number) you should get a text!

And a killer autostart script from here (thanks Antoine Aflalo) and monit script from here (thanks Giovanni):

sudo nano /etc/init.d/node-red

#!/bin/sh
#/etc/init.d/node-red

### BEGIN INIT INFO
# Provides: node-red
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop the node-red server
### END INIT INFO

NAME=node-red
DAEMON=/usr/local/bin/node
SCRIPT_DIR=’/usr/local/lib/node_modules/node-red/’
OPTIONS=”–max-old-space-size=192 red.js -v”
LOG=’/var/log/node-red.log’
USER=root:root
PIDFILE=/var/run/node-red.pid

. /lib/lsb/init-functions

start_daemon () {
start-stop-daemon –start –chdir $SCRIPT_DIR –background \
–chuid $USER \
$START_STOP_OPTIONS –make-pidfile –pidfile $PIDFILE \
–exec $DAEMON — $OPTIONS >> “${LOG}” 2>> “${LOG}” </dev/null
log_end_msg 0
}

case “$1” in
start)
log_daemon_msg “Starting daemon” “$NAME”
start_daemon

;;
stop)
log_daemon_msg “Stopping daemon” “$NAME”
start-stop-daemon –stop –quiet \
–chuid $USER \
–chdir $SCRIPT_DIR \
–exec $DAEMON –pidfile $PIDFILE –retry 30 \
–oknodo || log_end_msg $?
log_end_msg 0
;;
restart)
$0 stop
sleep 5
$0 start
;;
status)
status_of_proc “$DAEMON” “$NAME”
exit $?
;;

*)
echo “Usage: $0 {start|stop|restart}”
exit 1
esac
exit 0

And now we can do a:

sudo chmod 755 /etc/init.d/node-red && sudo update-rc.d node-red defaults

to install the startup script. On reboot, the node-red daemon should start, along with the mqtt & text message server.

To configure monit, edit /etc/monit/monitrc if desired to set the time intervals of the checks and to set the users who can do web monitoring. Add a line at the end to include an additional directory for service definitions:

include /etc/monit/monitrc.d/*

Finally create a file to configure the monitoring of node-red (again tweaked from Giovanni to cope with authentication enabled on the pi) with sudo nano /etc/monit/monitrc.d/node-red

check node-red with pidfile /var/run/node-red.pid
start program = “/etc/init.d/node-red start”
stop program = “/etc/init.d/node-red stop”

if failed url http://username:password@localhost:1880 timeout 10 seconds then restart
if 3 restarts within 5 cycles then timeout

If node-red dies, then monit will start it up again within 30 seconds. Monit can be monitored and controlled remotely quite easily on port 2812.

To send a text message via node red, just configure a file node to save a file to the /var/spool/gammu/outbox with the format OUT############.txt where the hashes are the number you want to send. Once the message is sent gammu will automagically move the file to the sent folder for you.

The post Setting up a Pi from bare Raspbian to work as a Node-Red controller appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2013/11/setting-pi-bare-os-work-node-red-controller/feed/ 0
raspberry pi running node-red, wiring-pi to pwm control a light https://l0l.org.uk.archived.website/2013/09/raspberry-pi-running-node-red-wiring-pi-to-pwm-control-a-light/ https://l0l.org.uk.archived.website/2013/09/raspberry-pi-running-node-red-wiring-pi-to-pwm-control-a-light/#respond Fri, 20 Sep 2013 13:27:11 +0000 https://l0l.org.uk/?p=57 OK so putting node-RED on the raspberry pi was almost as easy as getting it onto my computer – see previous post here. I started with the occidentalis distro from adafruit – and to install node.js itself I needed to use different package to match the pi wget http://node-arm.herokuapp.com/node_latest_armhf.deb sudo dpkg -i node_latest_armhf.deb but apart […]

The post raspberry pi running node-red, wiring-pi to pwm control a light appeared first on layer zero labs.

]]>
OK so putting node-RED on the raspberry pi was almost as easy as getting it onto my computer – see previous post here.

I started with the occidentalis distro from adafruit – and to install node.js itself I needed to use different package to match the pi

wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb

but apart from that things were fairly smooth, I farted around for ages trying to get a manual build of wiring-pi to be recognised, then just randomly tried a

npm install wiring-pi

to install the library directly, and that worked great!  I edited the node-RED settings.js file to add in the ability to use wiring-pi in the global context, and then restarted node-RED.

I wanted both mosquitto and node-RED to start automatically on boot, and rather than use rc.local I created a file in /etc/init.d like so:

sudo nano /etc/init.d/mqttstart
sudo chmod 755 /etc/init.d/mqttstart
sudo update-rc.d mqttstart defaults

the mqttstart script just consists of:

mosquitto -d
cd /home/pi/node-red
screen -dmS red sudo node red.js

So after all that setup; I loaded up node-RED and copied in the blink example and got that working!! but then changed the code around a bit, and looked into the pwm capabilities of the pi. Turns out it has one built-in pwm function and the wiring pi library provides soft-pwm on other pins.

So I changed the pin to pin 1 (wiring-pi convention) and hacked at the blink example function code to show the pwm functioning:

node-RED code for pwm light
node-RED code for pwm light

Here is my code, as per the example on the node-RED documentation, just copy the text into the clipboard, then select import from clipboard in the top right and paste it in:

[{"id":"ce4d5b27.31b2a8","type":"function","name":"fade LED up and down on input","func":"\n// select wpi pin 1 = pin 12 on header\nvar pin = 1;\n\n// initialise the wpi to use the global context\nvar wpi = context.global.wpi;\n\n// use the default WiringPi pin number scheme...\nwpi.setup();\n\n// set the mode to pwm output\nwpi.pinMode(pin, wpi.modes.PWM_OUTPUT);\n\n// do the fade up/down in brightness thing\n\nfor (var i=0; i<256; i++){\nwpi.pwmWrite(pin, i*4);\npausecomp(5);\n}\nfor (var i=256; i>-1; i--){\nwpi.pwmWrite(pin, i*4);\npausecomp(5);\n}\n// we don't \"need\" to return anything here but may help for debug\nreturn msg;\n\n// timing function hack kudos Pavel Bakhilau via Sean McManus\nfunction pausecomp(ms) {\nms += new Date().getTime();\nwhile (new Date() < ms){}\n} ","outputs":1,"x":505,"y":370,"wires":[["6c906a60.936f94"]]},{"id":"df3260b7.20cda","type":"inject","name":"tick","topic":"","payload":"","repeat":"1","crontab":"","once":false,"x":291,"y":344,"wires":[["ce4d5b27.31b2a8"]]},{"id":"6c906a60.936f94","type":"debug","name":"","active":true,"x":730,"y":385,"wires":[]}]

And now it works to light an led progressively.

Then I replaced the directly driven led with one driven by a TIP120 transistor – keeping a resistor (820Ω) in place to limit the current out of the pi. I haven’t got a convenient 12V load to test it with right now but here’s the same led but with a lot more current drive potential!

TIP120 driving an LED from the pwm pin of raspberry pi
TIP120 driving an LED from the pwm pin of raspberry pi

As a nice way to check my sanity, I set the light onto 100% and measured the current drawn from the pi – my cheap multimeter measured 2.31mA which is gratifying as my calculations here predicted 2.3mA! Way to go theoretical predictions!

The post raspberry pi running node-red, wiring-pi to pwm control a light appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2013/09/raspberry-pi-running-node-red-wiring-pi-to-pwm-control-a-light/feed/ 0