Having started putting together “the script” a long time ago, long before the Raspberry Pi 3 came out – and having developed it to handle a wide range of boards and scenarios including of course the Pi3, I found it interesting to return today to installing “the script” on the Raspberry Pi 3 – and of course I wanted to ensure that nothing had changed recently which might stop others doing the same.
Some time ago I wrote a blog entry about garden sensors inside of which was buried some information about using Grafana and InfluxDB. At the time the install was not that easy – and when along came STRETCH for the Raspberry Pi (2 and 3) it got worse.
However, reader Antonio and I have been working on this and we have an install for the latest Grafana with Influx.
If any of you have installed the new “Stretch” version of Raspbian on the Raspberry Pi, you may have noticed a slight issue with the wiringPi GPIO utility.
I’ve been using the likes of FriendlyArm boards and similar for so long now, struggling at first with GPIO and I2c and as regular readers will know, finally pretty much mastering it due to hard research and more importantly, the works of people you’ll find links to in other articles in here….. that I’ve pretty much ignored the actual Raspberry Pi for some time.
Until this week when my friend Jonathan sent me a Raspberry Pi 3 to check, as he’s been having trouble with “the script” and I could not help as my RPI2 installations worked just fine.
Just bought a new Raspberry Pi 3 with WIFI and Bluetooth? Using it in a project with serial? Happy?
Well, you might not be so happy when you find out what I just found out. I had my Node-Red project that has been controlling the house for around 18 months on a Pi2 and I was starting to have issues - I thought it time to upgrade. So I made a new installation, faithfully copied everything over, plugged in the board… everything was fine.
Except it wasn’t – nothing was coming out of the serial port. Well, it turns out they stole the serial port for the Bluetooth. There is a second port – of a kind – which can be set to work with the GPIO pins 14 and 15… but Node-Red serial node was NOT having it – I put a scope on the output – nothing. I followed instructions to use an alternative “serial port” – which appeared and – the Node-Red Serial port input would not recognise it.
Anyway, it isn’t all bad – thanks to Dave at IBM who put me onto this link…
Ignore most of the content and head to the end – Answer number FIVE. This got me back up and running with a high speed serial port – but – no Bluetooth of course. I’m assuming I can just stick in a Bluetooth dongle – time will tell.
Essentially assuming an up to date Pi3, the key line is the one where you add
to the /boot/config.txt file.
I’m liking FriendlyArm more and more (I’d like them even MORE if they’d put more RAM in their boards) but at least, for today, I’m up and running.
If like me you are not THAT familiar with I2c, you might find the results of my experiments interesting and perhaps even useful.
If like me you are not THAT familiar with I2c, you might find the results of my experiments interesting and perhaps even useful.
So I bought a couple of these i2c port expanders from China – mainly because I wanted something simple to mess with i2c on the ESP8266. It occurred to me that if I could get these working on a Pi, so I was sure of the addresses and commands etc., then on the ESP, I’d then get the confidence to do something more dramatic on the ESP8266 with i2c.
So ignoring for a minute the interrupt capability, these are pretty basic devices – using up 2 port bits (SDA and SCL) on your Pi or ESP, send an i2c start to them followed by an address then a byte to them – and the outputs light up accordingly. Set the outputs to 255 and read back a byte and you get the state of the pins as inputs. It doesn’t get any easier.
Well, not unless you completely mis-interpret the addressing as I did and spend ages chattering away to the wrong address. Anyway, let’s not dwell on that.
I noted that the outputs are HIGH by default. Also note that in my experiments I have set the 3 DIP switches to ON (NOT as in the photo above).
Armed with the latest version of Raspbian Jessie on a pi2 or Pi3, connect ground on the device to ground on the Pi, VCC to 3v3 on the Pi, SDA to SDA (blue) on the Pi, SCL to SCL on the Pi. Simples. The boards have built-in pull-up resistors for i2c (which could pose an issue if you parallel a bunch of them up of course) so that’s it – no other new components needed other than a LED for testing. I used a 470r resistor in series with the LED.
Open a terminal on the Pi and type:
That starts the new GPIO library daemon running in the background.
Now here is a short file that will set all the outputs to 0 – running Python…
pi1 = pigpio.pi()
Nice but then my pal Peter Oakes pointed out to me that I’d end up loading the entire Python environment every time I wanted to change an output.. so I started experimenting with C code… just turning GPIO18 (on the Pi) on and off for starters…. see the line that says gpioWrite(18,0); that turns the port off. Substitute a “1” to get the opposite effect. All of this worked a treat.. “b” here ends up containing a handle.
if (gpioInitialise() < 0)
puts("erm no"); // pigpio initialisation failed.
// pigpio initialised okay.
The code above once compiled failed the first time – I realised you must NOT have the daemon running when using this. so a quick reboot later and I was in business.
Oh, here’s how to compile a simple C program like that – make sure it’s a text file, say in your /home/pi directory.
gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 –lrt
See where it says “prog” – change that to the name of your program. Takes seconds.
Anyway, I was just about to set everything up in C for i2c etc. when I discovered… PIGS
pigs w 18 0
pigs w 18 1
Note – no sudo needed for the commands and presumably one would run that daemon (pigpiod) at startup. This looked like a nice simple route – dead easy for Node-Red as you can just issue the commands in an EXEC function and pass the parameters in the payload – so next would be to try i2c….
pigs i2co 1 39 0
pigs i2cwb 0 0 0
pigs i2cwb 0 0 255
pigs i2cwb 0 0 1
pigs i2cwb 0 0 2
pigs i2cc 0
The first command visually returned 0 – hence my use of 0 later in the code as the “handle”. I order, I set the expander to all off, all on, then the first bit only on – then the second bit only on and finally I closed the handle.
Something to note is that I2c lines need pull-up resistors – and this board has them already built in – unfortunately they are 1k pullups – fine if you only have one board, not a lot of use if you want to put several in parallel. After discussion we think that possibly the two relevant resistors might be replaced by 10k in which case you could then run several in parallel (with different addresses) but we’ve not tested that.
Oh, making that daemon permanent… I did that with a command line edit “sudo nano /etc/rc.local” - and added the line “sudo /usr/bin/pigpiod” – and rebooted…. no problem.
Update November 9, 2016
The final stage of this experiment gives my ESP8266 software the ability to achieve the same thing, losing 2 wires to get 64 new ones (YES, 64), a net benefit of 62 I/O lines, could be worthwhile as the ESP8266 isn’t exactly brimming with IO lines.
Above you see (blue) our ESP-12 board, fastened to an FTDI for power, and wired by jumper to one of the PCF8574T boards - clearly you'd need 8 of them to get 64 lines and I'd be wary as they have pullup resistors on the data lines. I'd remove them on all but one.
With a typical Chinese PCF8574T board which includes pullups, I’ve added new commands to the ESP8266 Home Control software as of my software version 1.6.52 – the xport command.
sets the lowest bit of the first (address 39) expander high (the 0 is a mandatory argument above – see future blogs) whereas:
returns the state of the first (LSB) bit of the first of up to 64 bits.
On power up these devices are HIGH - and the software defaults to high on power up. If you mess with a port bit, you need to set a bit high before you can use it as an input. Here is the datasheet for this chip – and here is a typical Chinese expansion board. With GPIO4 on our little boards hooked to SCL and GPIO5 hooked to SDA – the new commands work a treat.
In the above photo – address 39 equates to all DIP switches set to ON (that’s high or 7). If you set number 3 to off – that is address 38 (bits 8-15) etc. (simple binary selections – you can make the device work as anything from 32 (all switches OFF) to 39 (all switches ON) but before you go connecting eight of them up – bear in mind the comments about pull-ups above.
I’ve been doing a little more on these as you’ll see in other parts of the blog – but the upshot is – you have to ask yourself if these are worth the money. In my original blog I pointed to an Ebay price of £2.35 - but in fact from AliExpress they are only £1.20 and so I’ve amended the link in the blog accordingly. However as you’ll see in other blog items – as I’ve learned I’ve realised they are not necessarily the best bet. I’ve now made a simple “Nano i2c peripheral” from a Nano board – and they cost just a few pence more – but you can make NOT only an 8-bit expander but also get some A/D, some PWM and some A/D thrown in – hell I’m even putting an LCD display driver in just for the sake of it – and I’ll call it the kitchen sink peripheral.
However if you do like the look of these chips, you’ll note they say they work on 100Khz I2c. That of course is true and I’ve not experimented with anything other than close up – lets say less than 250mm away – but I’m currently running them a HELL of a lot faster than that. I’ve only speeded up the clock for writes and reads – note the wide bits around the edges but still – quite nippy.
Just a very quick one (and somewhere to park the conversation)– there’s a new Raspberry Pi update out promising a new smoother, simpler look, better video etc. Up to now it looks like the claim is correct.
I have several RPI installations…including TightVNC and so I didn’t want to lose that. I did however, want the Chromium browser. I’m not interested in PI-HATs and similar so here’s all I did to get the upgrade…
sudo apt-get update sudo apt-get dist-upgrade sudo apt-get install -y rpi-chromium-mods
That’s it – nothing more –takes a few minutes all in - there is one Y for confirm and a reboot – and Bob’s your uncle. To test things out I went to the BBC website and of course got the usual message about Flash – things haven’t change there much – but with a signup for the BBCs “beta” HTML5 version (it’s a bit late for a beta, isn’t it? HTML5 has been out for longer than I can remember) all is well, videos no problem!
The new interface is to be given it’s own name “PIXEL” – that’ll make searching for information about it a whole lot of fun… they could have picked something unique like “PIXL” or something – however it all seems to work – more modern appearance – slick – file manager is nice and apparently if not faster it is at least no slower than it’s predecessor so really no reason not to go for it.
Here’s the link in case you need more info. Given this new look – with hardware graphics support – which likely means you could be using your Raspberry Pi 3 for a media centre… AND the best backup program out there which can replicate the system even on a different size SD -something as far as I’m aware NO-ONE else has – one has to ask – what are the other SBC board manufacturers going to do now!!!
Here’s a bit of a reversal.. normally I steer clear of the UK for pricing as we tend to pay over the top… I can’t help thinking I’m reading this incorrectly….
However – here above is RS Components latest pricing for the Raspberry Pi 3 – the latest model – at just over £27
And that’s fine – compares to what, say the USA would pay. I think I bought a model 2 last year in the USA for slightly less.
But check this out…
Claiming 65% off and charging £38 for the old model 2 !!!
Am I missing something here?
The funny thing is – after seeing this – I found more – I found a Raspberry Pi 3 all on AliExpress – for £29.29 with free shipping – which is a GOOD price – then the older Pi2 for an amazingly high £53.98 (they are kidding, right~?) – the two prices sitting right next to each other!!
Oh, here’s the link for the 3 in case anyone’s interested…
I have a Raspberry Pi 3 and recently bought a 5” screen from here at sub-£20:
While the instructions on Ebay totally miss talking about the touch screen which does not work by default, this blog entry - https://blog.ask-a.ninja/?p=48 is absolutely bang on – the screen instructions are more precise than the Ebay ones AND you get the touch screen working – note the calibration information.
Here is the setup.. in boot/config.txt. I didn't bother uncommenting the existing ones - I just added this lot in - then rebooted.
Once I got that far and rebooted – the screen registration was SPOT ON. The TERMINAL I found too large but you can resize that – there’s a lot of stuff out there about changing it’s size in the config file – well, alI can say is that in RPI3 at least it does not make a bit of difference. I think it’s fair to say that 480px is a little on the low side so I don’t think that detracts too much from the value. A solution turned out to be simple – in the /boot/config.txt file
# uncomment to force a console size. By default it will be display's size minus
This made for a rather small font but solved the problem. I’m sure a little tweaking would make it even better.
Why oh WHY do they keep that utterly USELESS Web browser in Raspbian? I powered up my new Raspberry Pi today on my new 5” LCD display and tried loading up Node-Red on the browser.
That went well until I tried to edit a function – blank white window. I figured it was the LCD – so I tried it in TightVNC instead – still a white window.
I remembered that on my non-Pi machines they install Iceweasel – so off I went to get Iceweasel instead.
Surprised to say the LEAST when I installed the latter it also came with FIREFOX!! Now I’m a Chrome man but there’s nothing wrong with Firefox and so I was delighted to see that. I tried Node-Red on it and LO – worked a treat. So I’ve taken off the horrible default browser from my Pi3 and put Firefox up there instead. Looks lovely on the top.
While I was on, having learned from the experience with the NanoPis – I installed WICD while I was on – nice visual setup for WIFI.
And there it is – my sparkly Pi3 home screen.
But here’s the BIG thing – NOW all the BBC’s videos work all of a sudden – gone are the “you need Flash” messages – even BBC videos work (mind you – they won’t work on the little 5” LCD – back to “you need to install Flash” – which then doesn’t work. I’ll put that down to the LCD and have griped to my Ebay supplier. More on the touch screen later – it’s a winner.
You could be forgiven for thinking I’ve gone off the boil as I’ve not written much in here this week… far from it in fact. This week I’ve been working on my ImperiHome setup and the new Raspberry Pi software.
ImperiHome: In case you don’t know, ImperiHome is an app for Android and IOS that enables remote IOT control. It does this by trying to appeal to just about every system out there, none of which I use. I’ve taken the approach of having IBM’s Node-Red control everything – and thankfully ImperiHome has a generic API to allow control if you don’t have ANY of the devices it supports.
I’ve written more than one item on this subject and I have to say despite a rather lacklustre approach to answering people’s questions by their team and something of a lack of generic controls (such as a momentary push-button), the product actually works and works quite well. I have RGB lights, relays, sensors and a host of gadgets attached to Node-Red. Those which are required to just come on and off at varying times of the day are controlled by my BigTimer (which, recently updated, works a treat – or rather, it does if you remember to set the time zone when setting up the Pi as I found out last night when all the lights were still on at 2am, defying all explanation until my wife said “did you ever set the clock on that thing?”).
Those gadgets which require interaction are controlled by ImperiHome on my HTC Smartphone.
On the subject of Node-Red, we are promised non-volatile global variables in future by the Node-Red team and I for one can’t wait – but for now I’ve just completed a function to save a global object (buffered in time) when any change is made. That global object forms the variables used in my ImperiHome project – so now at last, the phone is always aware of the state of my lights – a handy thing. Essentially the object contains a counter which is set whenever any other variable in the object is altered. This is monitored by a timer which also kicks in on power-up. If the counter is true, it is decremented – if it hits zero I update the file on SD which contains that object. I also check to see if the file exists – and if not, I create it. If the file DOES exist and the object doesn’t – I populate the object. So now, my lighting and other settings can survive power-cycling.
Raspberry Pi: On 10/05/2016 the Raspberry Pi foundation put out a new release of Jessie (Debian) and with it, items you might expect like better support for Bluetooth etc., but then something I wasn’t expecting – a decent backup program. After (what seems like) years of struggling with arcane Linux commands some of which I never really got to grips with and hence never achieved a satisfying backup solution, at last, a simple push-a-button backup program that not only allows for live backups, but also allows for the use of varying size SDs both larger and smaller.
WHY did this take so long… I can’t tell you how this has changed things for me – backup time is reduced, no need to shut the house controller down when I’m doing backups, the use of smaller SDs, running multiple copies of the same software on different boards – the list goes on.
But for days I’ve been struggling with upgrades – the backups just did not want to accept upgrades (apt-get-upgrade) and when they did, invariably Node-Red would fall over with missing nodes etc. I didn’t know if it was the backup program or what… (I knew it was not the SDs as I use only good ones). Well, it turns out that my script was in need of bringing up to date. I still scrap node, npn and node-red and re-install to get the very latest but I’ve done it a different way, more by trial and error, but I got there in the end and now my backups and restores are working perfectly. I’ll publish the updated script soon, replacing the older one and I’ve added some tricks I’ve picked up along the way from readers like you.
I started this blog entry before our BBQ yesterday and here I am up early on a Monday morning finishing off the job. The lights worked a treat last night now the clock is set correctly – thanks to NTP it will now stay that way.
Coming up this week hopefully – a couple of new boards from Friendly Arm, the new Nextion display and more. But first things first, some supply shopping, I’ve lost a filling and Maureen’s done her foot in – this should be good – dentist and hospital – in Spain (and not in the tourist areas where they speak English).
So much happening right now – the new Raspberry Pi 3 once again sets the bar with improved performance, Bluetooth and WIFI as standard. With up to 10x the speed of the original Pi we can do even more serious work with these devices.
Please note before proceeding – apparently the Blynk team plan to charge for the use of this app – it is not clear if this means using their server, using a local server or both? And they claim that new widgets will be included in a monthly deal – but WHAT new widgets and in what timescales? – as the Blynk app moves from free to paid I think they will find people want more definition of what is included and when. A one-off fee is one thing – an on-going payment is altogether something else. http://community.blynk.cc/t/blynk-will-introduce-paid-subscription-in-q1-2016/3177
The ESP8266s are looking (depending on which software you use) to be very reliable to – so that is both the central control and peripheral activity side of things more or less in place.
Where we are still falling down IMHO is the visual interface side – that is – remote control by phone. I’m interested only in Android but I’m sure the same applies to IOS.
At the turn of the year it was looking like a neck and neck race between a small number of systems, node-red-contrib-ui for those inclined to doing a spot of programming and Blynk for those who are more concerned with the visuals. I’ve looked at several other packages but to be honest either the visuals were just pretty poor or the technology not too well thought out etc.
We’re not there yet. To my mind the one with the most hope was, until recently node-red-contrib-ui but since January there has been little or no sign of the author and no further developments that I am aware of (though I did hear a rumour that it might become a permanent part of Node-Red – let’s hope this spurs major new development) – this is a great shame as there was a heavy conversation going on with big improvements almost there – and then it all stopped. This is not new – I was convinced at one point that NETIO would be the brave future but development on that seemed to stop some time ago despite being commercial.
That leaves us with Blynk and a few others. Blynk is almost there. It works with the concept of a central server which knows the states of various devices, accepts updates and relays that to the APP. I pushed hard on this to make sure that regardless of whether the App was on or off, the state would be stored and the App would reflect changes when brought back to life. This was considered an edge request by the designers but they implemented it anyway and between that, improvements to the local version of the (small Java) server (which can run on a Raspberry Pi) and some sterling volunteer third party work to bring websocket-based communication back to Node-Red, the App is looking like a clear leader – but not perfect yet.
I recently contacted Blynk and was assured that at some point they will fix the current issue – that being – they expected people to use buttons for ON and OFF scenarios. I’d not twigged to this issue until recently when I finally started putting together a set of Blynk controls for my various gadgets.
One of the items I use a lot in my Node-Red applications is my own BIGTIMER (node-red-contrib-bigtimer) and that can set, say a light, to come on and off at set times during the day – for example coming on at lighting up time and off at midnight. But like all timers – one must have an override facility – and so it is with bigtimer – I can inject text “on”, “off” and “auto” into the input to manually override the timer or send it back to auto.
Well as you can imagine – that is simple to implement with 3 buttons – but having them say “ON” or “OFF” just does not apply – similarly for heating control you might have “up” and “down” buttons.
Blynk say they will not only implement variable text in the buttons but also icon graphics… well, can I put a request in now – if these are to be fixed icons – we need a full set of remote control icons – ie stop, pause, start, ff, rw etc. For text the best option would be freeform…. or NOTHING – text in momentary buttons just doesn’t make sense to me. A change of colour when being pressed is good and they’ve implemented that.
It would be nice if they had a smaller button as well – and the RGB control is just WAY too big – but looking at the alternatives – Blynk are to my mind still ahead of most.
I’ve looked at several alternatives – but right now most just not cutting the mustard. Either too complicated to setup, too limiting, unreliable or just not finished – and that happens a lot. There is just one out there that might just blow Blynk out of the water and you’ll see my videos and this blog commenting in the future – the app is called Imperihome and thanks to a small number of us working together, there is now good support via Node-Red for this App which is available for both IOS and Android – on the surface it blows even Blynk out of the water. Time will tell.