I’ve had a return to experimenting with my “nano peripheral”. You may recall I was buying all sorts of parts – A/D converters, port expanders etc. to help with my solar monitoring – and some time ago I had a shot at making an I2c peripheral using an Arduino Nano (you don't need to look this up).
It even went as far as putting a display on the board – which I never ended up using and it occurred to me that it might be better to have the extra pins. Hence this new version of the NANO section of my home control diagram – but this is stand-alone – as long as you know how to use I2c you can use this.
Actually this might make a useful peripheral to control from one of the many single board computers such as Nanos, Raspberry Pi etc. as most can handle I2c and usually in something simple like Python so this might make a useful alternative to messing around with the pins on the main board - and let's face it, PWM on most of these boards is not that clever due to the operating system not really being real-time. I recall messing around with a NEO and I could get one hardware supported PWM output, the software PWM was atrocious. So immediately here you get half a dozen perfectly useful 8-bit PWM outputs on a little board costing less than a beer.
So above you see where it fits in the scheme of things – my general controller is an ESP8266 board with a boatload of properties – one of them being able to talk via I2c to various devices.
So the idea of this device is a “jack of all trades” - unfeasibly cheap yet having useful specs – for example the A/D converter inputs are 10-bit – perfectly adequate for measuring battery voltages (you might need resistive dividers as the Arduino A/D input is 1.1v max in this case for value 1023).
This new device then is (by default) device 9 on the i2c bus though you can change that. Some pins are useful – others not so much – here below is an image of this “peripheral” which is nothing more than a programmed up Chinese £1.50 Nano board.
So as you can see (and bear in mind that not all NANO devices have the same pin-out) I’m making reasonable use of the pins. With I2c you can set outputs, read inputs, read analog inputs and set PWM outputs as well as sending a message out through the serial port. Of course this could be taken A LOT further as the code is not that complicated.
Don’t forget however if you are using this on it’s own with no other I2c devices – you need resistive pull-ups on SDA and SCL. I use 2k2. And of course you may want more than one..
If using this with my ESP8266 control software you need version 1.91 or better (updated 11/06/2017) as there was a timing error with earlier versions which prevented ADC reading.
I’m connecting this to the 5v supply on a WEMOS D1 (this Nano has it’s own 5v regulator) and no conversion of voltage levels is needed. The Home control manual has been updated so you have the commands in there – and the source code for the peripheral – likely to grown in the future – is below…
I added in servos at the last minute after an almost expensive learning exercise. You can control servos on any of the pins 2-13 - that’s a lot of servos – but as I found out – you can’t just run servos off the supply, say USB to the processor board. These things can take a fair bit of current (not control signal but power) so make sure they have adequate power – just one of them I tried was using 250ma when moving from A to B and that was just a little £4 toy servo. Consumption when still was nothing significant.
I learned a lot doing this – a quick look through the web showed that Arduino supports only 2 servos at once – and that PWM works – well both of those are WRONG. PWM does not work and made one of my servos get very hot… and the info out there about how many servos the Arduino can handle was also out a date – a simple trip to the Arduino site itself shows that the standard servo library can handle lots of them. So PWM is about the ratio between the ON time and the OFF time – servo driving is about the actual on period.
So - I made servo control available on all of the pins up to and including 13 – so that’s 2-13 – not just the pins that handle PWM (use ANY servo and you lose PWM on pins 9 and 10 – no big deal there).
On wiring – and this will vary from servo to servo – I found (despite not finding this on the web) that of the 3 wires – brown, red and orange – the brown was ground, red was +5v and the orange was a signal wire I could put straight onto a pin on the nano.
One of the annoying features of some Nano boards is lack of power and ground spares. Check this one out -
I have 780 bytes of RAM left which puts a limit on what I can add to this – what other features do you think might be nice to add to this – whatever they are they can’t take up too much processing time… maybe an edge-triggered counter on one of the inputs? What else?
Latest version stored here -https://bitbucket.org/snippets/scargill/kRg5o