Cheap IOT Solution and the M1

FriendlyArm NanoPi M1Recently I blogged about an update to pricing for the Sonoff mains control units – now down to £3.50 ($4.85) and our readers even reminded us of some potentially great software for those units (as well as my own but then mine is more of a kitchen sink approach and the Sonoffs have only 1Meg of Flash so you lose OTA). Lots of comments – all good.

Updates at the end – slowly cracking the GPIO – got some I/O working!

Meanwhile, you’ll have noted elsewhere on the blog that I’ve found a fabulous, hassle-free battery backup solution in the Ravpower units.

Much MORE Cheapness: And now…. a possible CHEAP alternative to Raspberry Pi for a central controller.

I know – heard it all before… so have I but read on…

As some of you know, I’ve pretty much settled on Debian as the base for a central controller using Node-Red, SQLITE, Mosquitto MQTT and Apache/PHP (to run the likes of PHPLiteAdmin) and I’ve done that based on a Raspberry Pi2/3 for a number of reasons – including working 3.5mm audio, speed, ease of use, support, hardwired network (I think the central controller should be hardwired as it has to be rock-solid), less to learn and… well you can read all my reasons elsewhere.

Well, I’ve been experimenting with the latest FriendlyArm units and one of them stands out a mile as a possible contender for cheapest central controller (Pi Zero is out as it does not have an Ethernet connector, audio connector etc and by the time you add in connectors and the other stuff it is no longer cheap).. How about a Pi lookalike that is SMALLER than a Pi, for well under £10 + post – hence when put together forming what HAS to be the cheapest overall IOT setup on the planet??

Check out the FriendlyArm NanoPi-M1 – a small, square ARM-based unit with the following Spec (you can read the full spec on their site – these are just the important bits)

  • Allwinner H3, quad-core Cortex A7 running in this case – JESSIE
  • Mali 300 graphic chip
  • 512MB RAM (1Gig available)
  • 10/100 Ethernet
  • 3.5mm or HDMI audio
  • Mic
  • IR Receiver
  • USB * 3
  • HDMI out
  • Camera interface
  • Debug serial and GPIO

They are the important details – what IS equally important for me is that it works with my installation script – hence the whole setup as described above can be done easily in maybe a couple of hours. https://bitbucket.org/snippets/scargill/KqgAe – you should be familiar with running scripts before tacking this – this one was meant for the Pi – not the M1 – and you absolutely must read the comments as the script is general in nature – for the M1 you need to create the Pi user and groups manually (easy –underside of NanoPi M1 commented in the script just to keep everything in one place) and set up the hostname (2 files ) to whatever you want – then copy the script over and give it the extra permission before running.   I’ve just got it working and can confirm that SQLITE and PHPLITEADMIN work (hence Apache and PHP), Node-Red, Webmin and Mosquitto all work and in Node-Red I can access THREE UARTS – the first one of four is for debug so you can’t rssily get to that but it beats having to disable it as on the Pi.  I can access Node-Red as nanopim1:2880

Not touched GPIO but that’s an issue for most non-Pi boards… hopefully someone can tackle that and make the GPIO available within Node-Red.  This is looking REALLY good.

Audio works – but (and I had this on the Orange Pi PC) there is a very short burst of sound on the end of the IVONA recording – it has to be some kind of special character getting through – it is most definitely NOT the MP3 playback and when Ivona processes the file name it adds nothing on…. anyway, something for the weekend as they say along with polishing this blog up – for now – it seems like it might be possible to make a minimal IOT solution with a central processor and some mains controllers for under 20 quid!!!!! Stunning.

As I was writing this, and as the Debian image available with the M1 is only 4GB long – I was awaiting info from FriendlyArm as to how to expand as you might find with a Raspberry Pi to the full size of the SD. There are solutions out there and if you’re going to live forever there’s plenty of time to understand most of them.

FriendlyArm came back to me this morning with a simple solution. My 8GB card was sitting with half of it’s space unavailable. Support sent me some instructions for sending data over the serial debug port – but it turned out this was just exactly the same as I could achieve with a terminal.

I typed:

sudo fs_resize

it was suggested I reboot – and lo – the full size of the SD became available to me – 8GB. I wondered if I could push my luck – so I used Win232DiskManager to make a copy of the 8GB disk…. and then copied that image to a 16GB SD. I installed the 16GB SD into the M1 – powered up and tried the same again.

sudo fs_resize

I have to say I was not expecting miracles – but the results were the same and after a reboot I had my normal 16GB SD setup, no problem.

You could of course install Armbian for the M1 which automatically resizes to fit the SD but I’ve not yet tried this to make sure my stuff works so you’re on you’re own there – I did install it and it does work as a desktop complete with Libre Office etc. if that’s your thing.

Lovely – and so here is a cheap way to get Node-Red and other tools running pretty much as if you were on a Raspberry Pi – except of course for GPIO. None of the usual Pi tools are available  – I’ve have settled for the command line PIGPIO or similar as you can call that from a node – but no – there still remains a pretty uncomfortable learning exercise perhaps with some compiling to get control over the GPIO. In this instance I don’t need GPIO so its not a problem but I do with the designers of these systems would recognise that Raspberry Pi has set the pace.

I have tested taking their MATRIX examples of C code – and loading them into the M1 and compiling using the GEANY editor that comes with the Debian setup – almost – and by copying all of the C files into one and adjusting include paths, I HAVE compiled some GPIO control that a ROOT user can use – but I just don’t know enough about the MAKE files to alter the path to do this properly.

Still – the point here is – the board seems to work well and is a CHEAP solution.  When I think of the hassle I had trying to get an Orange Pi to do this….

Benchmarks: So I guess what might be on your mind is… and so this cheap board – how does it compare to the Raspberry Pi 2 and 3?  I only had a 2 handy for testing and some tests too longer, some less, overall the M1 was MARGINALLY faster than  the Pi2 – I would go so far as to say they are comparable.

The test I’m running incidentally is a simple one – so you know..

To install (as root): apt-get install sysbench

To run (as root): sysbench –test=cpu –cpu-max-prime=20000 run

The M1 as an infra-red input which I’ve not tested – it would be nice if someone got that working with Node-Red.

GPIO Update: I was looking for stuff on GPIO on the M1 when I spotted in a forum the chap who developed Armbian talking – and he mentioned that the hardware in the M1 is the same as the Orange Pi One. Well, off I went in search of GPIO for THAT board.

I found this.

http://www.instructables.com/id/Orange-Pi-One-Python-GPIO-basic/

Now –  it still needs ROOT access which is a pain in the bum… but… I followed the instructions – as ROOT user – but in my /home/pi directory I’d created…. I went to the examples – and ran the one called blink_led.py – nothing – I tried every pin on the connector.  I figured nothing gained, nothing lost – so I change the port (led=port.X) to PA9 – LO – a flashing LED – PA19 (purely at random) – LO – another flashing light.

So a lookup table is needed to get the ports to match those on the M1 – and there has to be a way to avoid ROOT access as I want to call this stuff in Node-Red – but GPIO – works.  I’m sure there will be other stuff for the Orange Pi One by now – worth checking. I guess what is needed is some kind of daemon running as root user that an exe file running as a normal user can fire parameters at.  I’m sure someone cleverer than I could adapt PIGPIO or similar.

Anyway – there you go – just about everything a Pi2 does – and 3 fully usable UARTS and now – some GPIO. All for a fraction of the cost of a Pi2.  Got to be worth investigating.

and THEN I discovered THIS…..

http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=148

I typed as per the link:  

modprobe gpio-sunxi

The prompt returned as if nothing had happened – but then…. I noted on refresh that/sys/class/gpio_sw directory had magically appeared.

echo 1 > /sys/class/gpio_sw/normal_led/data

That’s one of the examples in that link – erm… NOPE it didn’t work…. no such thing.

So I gave this a try

echo 1 > /sys/class/gpio_sw/PA9/data

YUP – GPIOA9 on the connector lit up.

Sadly again – this stuff would not work for user PI but by the morning I’d pieced together that you need that “data” to have write permissions for other than the OWNER!

As ROOT – this works.

modprobe gpio-sunxi
/bin/chmod -R 0666 /sys/class/gpio_sw/*/data

So I put that into the /etc/rc.local file just before “exit 0”, saved and rebooted. LO and behold – it all works as user Pi !!! I can now at least do simple GPIO output from Node-Red using an EXEC node. Well, it’s a start!

I’ve tested the Pxx items available in /sys/class/gpio_sw and the ones that seem to work AND are on the connector include: PA0,PA1,PA6,PA7,PA8,PA9,PA21,PG6,PG7,PG8,PG9. I have avoided touching the UART pins as I think I’d rather have the UARTS available.

Of course at this point I’ve no idea how to READ one of those pins.

WiringPi and GPIO: I did originally try the adaptation of WIRINGPI here and hence the GPIO command line utility – which didn’t seem to object to any commands – but on the other hand didn’t do a THING with them.

Then armed with my successes above, I ran

gpio readall

This produced a list of states of pins with no resemblance to what I was using – but as I toggled PA9 on and off I noted a change from the readall command on GPIO.23.

Could it be:

gpio write 23 1

YES – it turned on PA9.

gpio read 23

YES, it returned the value.

gpio mode 23 in

The light went out and I realised that floating the pin would return 1, grounding the pin would return 0.

I looked for more info on WiringPi and found this – https://projects.drogon.net/raspberry-pi/wiringpi/the-gpio-utility/

With my pin set as an input – the pullup modes worked too.

gpio mode 23 up/down/tri

It turns out that what I was calling PA6 is called GPIO.7 in the WiringPi setup – and this is a PWM pin – could I be so lucky?

No. No matter what pin number I tried – setting PWM mode was not having it. Still – input and output – that’s a step up!! It also turns out that the second part of my rc.local work is NOT needed for WiringPi – just the first line (ie. the modprobe bit).

  • Pin 40 GPIOA14 gpio write 16 on
  • Pin 38 GPIOA15  gpio nothing default on
  • Pin 36 GPIOA13  gpio write 15 on
  • Pin 32 GPIOA7  gpio write 26 on
  • Pin 28 GPIOA18  gpio write 21 on
  • Pin 26 GPIOA17  nothing default off
  • Pin 24 GPIOC3  gpio write 10 on
  • Pin 22 GPIOA1  gpio write 0 on
  • Pin 18 GPIOG9  gpio write 27 on
  • Pin 16 GPIOG8 gpio write 26 on
  • Pin 12 GPIOA6 gpio write 7 on  (also PWM test pin see further down)
  • Pin 10 GPIOG7  gpio write 29 on
  • Pin 8 GPIOG6 gpio write 28 on
  • Pin 7 GPIOG11  nothing default on
  • Pin 11 GPIOA0  gpio write 2 on
  • Pin 13 GPIOA2  gpio write 6 on
  • Pin 15 GPIOA3  gpio write 3 on
  • Pin 19 GPIOC0  gpio write 12 on
  • Pin 21 GPIOC1  gpio write 13 on
  • Pin 23 GPIOC2  gpio write 14 on
  • Pin 27 GPIA19  gpio write 30 on
  • Pin 29 GPIA20  gpio write 25 on
  • Pin 31 GPIOA21  gpio write 11 on
  • Pin 33 GPIOA8  gpio write 22 on
  • Pin 35 GPIOA16 nothing default on
  • Pin 37 GPIOA9  gpio write 23 on

SO – then after all of this – one of our readers pointed me to a C program (see link below), easily compiled on the M1 or any other similar program that in this case simply runs PWM – of course – for a particular pin – but that’s not a problem – you could easily pass parameters – and one WILL.

NOW – that’s all fine and good but it will only run as user ROOT which if you are running node-red – is about as much use as a chocolate fireguard. Until I read THIS (for me game-changing) example about changing the user… so assuming our compiled program is called PWM and is run as ./PWM except it won’t as user PI for example…

http://www.orzalabs.tech/2016/08/20/testing-pwm-soft-with-wiringpi-on-a-nanonipi-m1/#more-70

Take your C program and

gcc -o pwm pwm.c -l wiringPi

sudo chown root:root pwm
sudo chmod 4755 pwm

I have to tell you I am WELL chuffed about THIS discovery because essentially it means I can make my OWN command line program… and customise it for different boards!!!!  AND it will run as user Pi on Node-Red using the EXEC node. Our friend might call the C program a very simple one – but that and the conversion to run as Pi or similar user – makes a BIG difference to a lot of us!!

I HAVE tried this and it DOES PWM modulate that pin – which means getting other pins to work should be a breeze.

THE ONLY PROBLEM is that this is software PWM – because despite the fact that the pin corresponding to 7 is in fact a PWM pin – if you try the wiringPi command for proper PWM – the system objects – and throws a message out – clearly the pins that can be set as PWM are predefined for another board… does anyone out there understand the Wiring Pi code sufficiently to modify it? If PWM won’t work properly – maybe the likes of I2c etc will suffer a similar fate.

But here’s the problem – though WiringOp just happens to work for GPIO on both the M1 and the NEO, and compiled WiringOp programs can be made to work as user Pi,  as the company’s Matrix software which DOES give you access to I2c etc. seems to have some issues with any other than ROOT access – and FriendlyArm do not currently know how to get around that.   The manual for the Matrix software is even now in Chinese only!

Facebooktwitterpinterestlinkedin

32 thoughts on “Cheap IOT Solution and the M1

  1. Good morning everyone, I have a nanopi M1 since a year but now is when I’m playing with it, and of course, I have several problems: one of them is that I modified the matrix file for the ir receiver to match the I/O port where is the embedded IR receiver, when I compile and build the modified .c file, the file generated is of the type “object code” and I need “executable” file type. I’m using geany, I know that wiring PI is easiest but I want to program in C.

    I have post in armbian forum and friendlyarm forum, also in linuxforum as I think I’m doing somthing wrong with debian. Can somone give some help with this?

    The post in friendlyarm is this:

    http://www.friendlyarm.com/Forum/viewtopic.php?f=49&t=987&p=2993&sid=8e802fb2eba10e05565cf1d747018467#p2993

    1. Thank you for that – I’ve written off to FriendlyArm to ask them if they’d like me to do a write-up on it! I think there’s an M3 on it’s way…

      1. NanoPi M3 exists since a longer time but they develop an A64 based board the size of NanoPi NEO/Air and another one I think I shouldn’t talk about).

        And I also fear M1 Plus isn’t announced yet. But I took the available information, spend half an hour and added it to our build system. At least with the last two boards I added (Orange Pi Zero and Nano Pi Air) we were lucky and got them running without having the hardware in our hands 🙂

        We’ll see. For your target audience it could be important that all those GbE equipped devices waste a lot of energy when they negotiate Gbit Ethernet connection. The PHY on the board then consumes ~350mW more. Can be adjusted in Armbian using our ‘h3consumption’ tool 🙂

  2. Does anyone managed to open serial ports?

    By GPIO data should be 3 RX/TX ports and one on Debug. I couldn’t use neither one of them…

    1. I think I have access to 2 of them on Node-Red… on my code (script) you’ll note I give Pi user access to the groups that a PI user would – that may have something to do with it – I can’t remember – either that or using SCP – go find the two serial ports and make them read write for everyone – either way I’m pretty sure I have access to 2 of them.

  3. Howay Peter!
    Tried your script on a nanoPi M1 & it worked 🙂
    It took a few attempts 🙁
    RTFM I tell myself…
    There’s a lot of stuff that I don’t need or want but I was struggling with node-red install & now I have it.
    Well done! 🙂

    1. Thank you – actually just fixed 2 minor sillies today so that’s good timing. New blog entry coming up – I’ve just got 16 channel PWM working on the ESP8266 – today home control – tomorrow…

  4. Your script was not clear everytime so i write here how to install just node red(within add an new user/group)

    My terminal was like that(i changed nothing to the users or groups):
    fa@NanoPi2:~$ sudo apt-get remove –purge node* npm

    ——————————————————————————————————

    sudo apt-get remove –purge node* npm

    curl -sL https://deb.nodesource.com/setup_4.x | sudo bash –

    sudo apt-get install nodejs -y

    sudo apt-get autoremove

    sudo apt-get install telnet

    sudo apt-get install -y build-essential python-dev nodejs

    sudo npm cache clean

    sudo npm install -g –unsafe-perm node-red

    sudo wget https://raw.githubusercontent.com/node-red/raspbian-debpackage/master/resources/nodered.service -O /lib/systemd/system/nodered.service

    sudo nano /lib/systemd/system/nodered.service
    **Change “User=Pi”,”Group=Pi” to “User=fa”,”Group=fa”**
    for save ctrl+o, ok and ctrl+x

    sudo wget https://raw.githubusercontent.com/node-red/raspbian-debpackage/master/resources/node-red-start -O /usr/bin/node-red-start

    sudo wget https://raw.githubusercontent.com/node-red/raspbian-debpackage/master/resources/node-red-stop -O /usr/bin/node-red-stop

    sudo chmod +x /usr/bin/node-red-st*

    sudo systemctl daemon-reload

    mkdir .node-red

    cd .node-red

    sudo npm install -g node-red-admin

    npm install moment
    npm install node-red-contrib-grove
    npm install node-red-contrib-bigtimer
    npm install node-red-contrib-esplogin
    npm install node-red-contrib-timeout
    npm install node-red-node-pushbullet
    npm install node-red-node-openweathermap
    npm install node-red-node-google
    npm install node-red-node-sqlite
    npm install node-red-desktop
    npm install node-red-node-emoncms
    npm install node-red-node-geofence
    npm install node-red-contrib-ivona
    npm install node-red-contrib-moment
    npm install node-red-contrib-particle
    npm install node-red-contrib-graphs
    npm install node-red-node-ledborg
    npm install node-red-node-ping
    npm install node-red-node-random
    npm install node-red-node-smooth
    npm install node-red-contrib-npm
    npm install node-red-contrib-file-function
    npm install raspi-io
    npm install node-red-contrib-gpio
    npm install node-red-contrib-admin
    npm install node-red-node-arduino
    npm install node-red-contrib-blynk-websockets

    sudo systemctl enable nodered.service
    **To enable to run node-red at every boot**

    ——————————————————————————————————

    I’ve spent over a day to know it was for what the #(sometimes it’s for the other board, like the creation of the pi user/group other time it’s for the Pi like in the Node-Red part), i hope i will save you this time 🙂

    1. Good – but that script is now out of date – made several changes in the last couple of days – always best to provide feedback for the original..
      1. Desktop does not exist.
      2. npm install node-red-dashboard needs adding to end…

      Would you care to look at the current one and tell me which lines you think should change…

  5. Hi Peter,

    I got a Nano Pi M1 (512 Mb), I installed armbian Jessie (http://www.armbian.com/nanopi-m1/).
    The OS is very good, after apt-get update I installed apache, ruby, rails, mysql, mqtt client, mosquitto. All of them works perfectly.
    I tried to install omxplayer, but I cannot install it. They told me that omxplayer is for raspberry pi only (I don’t understand why). Can you give me some sugestions how to play a mp4 file on HDMI output (I tried VLC, mplayer, but all of them complain about text interface)? I don’t want to install KDE or any other graphical interface (on raspbian lite on console only with omxplayer mp4 plays fine)

    1. Not sure as my kit is not in front of me but I think I had MPG player do that..
      Somewhere on the blog is the link to my SCRIPT and part of that is the IVONA mode and the MPG stript – they all worked for me..

      1. yes, the NEO, but i see the link correctly, tried 3 browsers and even from smartphone…

  6. Ordered an paid some of those….

    Unfortunately, very poor communication… No reply from them, no tracking number at all, it’s been a week now.

        1. I had the same problem. Ordered 17/6 then email on 21/6 requesting confirmation of address, then nothing – chased them on Friday and today an apology plus a free heatsink and confirmation of dispatch by DHL.

  7. Please give me some details about audio output quality and hdmi video quality. How are them compare to raspberry pi ?
    “Ubuntu-Core is a basic version which has support for Ethernet and SSH. FriendlyARM doesn’t provide technical support for it.” Did you try this Ubuntu version ?
    I think that core version is the best if you want to install only the services you need.

    1. Hi Ion… I’ve not tested Ubuntu-Core as I prefer Debian – it is much easier to make the unit look more like a Raspberry Pi and hence make use of some of the vast amount of support material for the latter.

      As for HDMI and audio out quality – both look and sound fine to me – but my monitor has bad overscan and I can’t figure out how to correct that so I TEND to use TightVNC to view the graphical interface.

      The Debian setup has no office stuff so really there isn’t that much overhead. I have in there – the ldxe graphical interface, node-red, sqlite, apache, various tools, mosquitto and more and I’m barely using 2.9GB… considering few people even sell SDs under 4 or 8 gig these days – an 8GB card which costs – what, £3 provides VAST excesses of space.

  8. @Peter Scargill: After modprobe you will get output only if the is error. You can use ‘dmesg’ to see what is happened when you modprobe module.
    Now may be not root is what you want, but just to adjust permissions on /sys/class/gpio_sw/PA9/data.
    Type ls -la /sys/class/gpio_sw/PA9/data and see what are permissions. If you don’t care and just want to everybody to have access you can try: chmod 777 /sys/class/gpio_sw/PA9/data (or 666). If you need just one user to have access you can try: chown pi: /sys/class/gpio_sw/PA9/data (if your user is pi).
    If something like that works for you then just put moprobe and chmod/chown in something like rc.local or whatever distribution used to be executed on boot and you are done.

    1. Garret, go directly to friendlyarm.com, they have an online shop. I can confirm that (for Japan, anyway), they do ship DHL and it’s definitely a lot quicker than the normal, “wait, wait, wait and then wait some more” for deliveries from the Middle Kingdom.
      If you’re getting the M1, then I’d recommend the $3 case, too (I think it’s the first 3D printed item I’ve ever touched, let alone paid for). The slots are all in the right places and SD access is easy (as long as you remember that the holder is on the bottom of the PCB, so the card needs to go in upside-down). The processor does run a bit on the warm side, so the $1 heatsink is probably a good bet, too.
      Be on the look-out for the verification, “Is this really your address and telephone number?” email from FriendlyArm. It seems that they won’t ship without verification from you (which is probably a good thing).

          1. …and now with price information, too:-

            256MB version – $7.99
            512MB version – $9.99

            Postage was $10 (DHL) to most of the world, last time I bought anything.

          2. Hi – right I’ve asked them for a sample to give it a go – bear in mind that there is no visual interface on this…it only works headlessly – and personally I’m not keen on the 256MB version – however – having gone through the pain of trying to get one of those A5-V11 boards running as a router.. it would be a pleasure to work with a really cheap board that actually has a reasonable amount of memory.

  9. I don’t understand how you did your SD card image manipulation on the M1. From what I can see, it does not feature an on-board SD card reader. Were you using an external card reader?

    1. If you’re referring to copying – I did that on a Windows 10 PC with WinDisk32Manager (as administrator) but the actual resizing command live.

      Sadly neither the M1 nor any other board I’ve tested has something as easy as the new Raspberry Pi SD Backup utility which runs on the graphical desktop and makes copying the live system to any size SD a snap. Maybe someone will port it over. I really don’t want to get into mind-bending terminal commands.

Comments are closed.