RCWL – 0516: Pretty impressive!

I find it hard to believe that you can buy a little radar-based motion detector for less than a quid (definitely don’t buy these off Amazon as they are at a rip-off price compared to AliExpress). And it’s especially difficult to believe that it works with no  problems! As you can see from the image, I’ve soldered a few headers onto the board so that I can plonk it onto a breadboard. I think my soldering station needs a new soldering tip as the solder kept rolling around the header. The solder eventually settled and took, but I was scared I was going to fry the board with the 360 degree heat from the soldering tip. I just left a time gap between soldering each header to let it cool down before moving onto the next one.

The first thing I did was to see whether I could get it working with an Arduino, and it couldn’t be any more simple. Check this page: RCWL-0516 microwave radar motion sensor for Arduino test and review for details. In essence you actually only need three pins for this to work. You need ground and vcc obviously, and then you just need to connect the ‘OUT’ to a pin on your Arduino. I believe you can attach the OUT pin to a PWM pin on the arduino, but I just attached it to pin 8 (a straight digital one) because that was good enough for my purposes. I uploaded the sketch (from the website link above) to my Arduino and sure enough, every time I moved, it triggered the LED on pin 13 on the board. I used a 10 k resistor on the OUT pin, which is overkill I think, but it was the only one I had to hand as I really didn’t want to go trawling through everything to find one. I think you’ll be able to use a resistor with a much lower value than that. In fact, I’ve read other articles where the author hasn’t used one at all.

Anyway, the next thing to do was to see whether I could power an ATMEGA328 from the 3.3v pin on the RWCL board. According to this link https://github.com/jdesbonnet/RCWL-0516, you could get 100ma over this pin. Only one way to find out! I set up the ATMEGA chip as you would normally do on a breadboard (there’s plenty of tutorials how to do this on the Internet, just Google it), and linked it to the RCWL board, with digitial pin 8 going to the OUT pin as before. Again I managed to get the LED on pin 13 to light up.

The next thing to try was to see if I can get a NRF24L01 chip running with the same set up, and after a day of trial end error, I managed to get a transmission working through my existing set up. Just need to refine the sketch now, but at least I got it working with the NRF chip which I wasn’t expecting to work given the small amount of power available from the 3.3v pin.

Will give a further write up and illustrations once I have done enough work on this to know it’s reliable.

LoRa32u4 by BSFrance.Fr (Blog Entry Part 1)

It’s early days for me with these devices at the moment, but  I have to say that I am impressed with their performance so far. For those who are not familiar with the LoRa32u4, they (and other flavours of LoRa devices) allow wireless communication over longer distances (than other wireless devices such as the NRF24L01), at least a few hundred metres through open air (I’ve read).  Hopefully this bodes well for the use to which I want to put these devices.

I am in the process of trying to replace a Raspberry PI Zero W as a gateway/base station for all the NRF24L01-based moisture sensors I’ve built for my greenhouse. I love the Ras Pi Zero W, it’s a fantastic piece of kit for the money and the WiFi has been absolutely rock-solid, but even though it uses less energy than the other Pi’s in the range, it still uses too much for my use, especially with the Arduino Uno plugged in to the USB port .

I’ve got an EC Technology 22 amp-hour power bank (which I can heartily recommend, they are brilliant power banks) which discharges in about 2.5 days with the Ras Pi/Arduino combination, and it’s just getting a bit annoying having to change the power bank every couple of days.

Although these LoRa modules are relatively expensive at the moment (around 12 quid from AliExpress), it appears that they would use much less power than my current base station, so it was worth the trade-off. I also would guess that these modules will eventually reduce in price when LoRa takes off a bit more.

When I ordered these modules, I forgot to purchase the little aerials you see in the image, but luckily I had some spare ones from a couple of Orange Pi Zeros, so that was cool. I’ve never been able to get the WiFi to work on the Orange Pi Zero, so that was okay.

Anyway, so far, I’ve uploaded an example sketch to the Arduino IDE (1.8.2) from Adafruit which used the RadioHead library with the RF95 set up, and it worked a treat.

I haven’t built my LoRa32u4-based gateway yet, that is to come soon, and I will write a post about it, but I did some decent testing to try and put the modules through their paces. I’ve noticed a slight issue when plugging the module into the power bank. The power bank would automatically switch off. This happened a few times while testing, which was a bit annoying, but when I plugged in the module at the same time as the Pi W, it didn’t switch off, which left me wondering if it’s using so little power that it’s falling below some kind of threshold and the power bank thinks there is nothing plugged in and switches itself off. Not sure about that at the moment.

But anyway, I got the module to ping the second module every second. The transmission is going through two housewalls, and three-quarters of the way down the garden about 20 metres away, and the modules performed flawlessly like this for two days.

So far, then, I am really happy with these modules. Hope this happiness continues as I build the circuit for my LoRa32u4-based gateway!

Realtime information from my car (Episode 2)

Welcome to the second installment! I made quite a bit of progress from the last episode and one small step backwards.  Once I’ve got something concrete together I will do a full tutorial

Over the last week I spent some time experimenting with all the technologies I’m using in isolation from each other, just to see if I could get stuff working individually.

First of all I saw whether or not I could get a 3G connection running. I plugged in the E1750 modem into the Raspberry Pi, ran a command to switch the modem to the correct setting.  After that, I downloaded the latest Sakis 3G script and ran the interactive script to generate settings for connecting the modem to the Internet. The most irritating part of this, once I’d got through the hassle of binding the modem to an RFComm port, was finding the correct APN settings for the EE network. I finally tracked them down to APN=everywhere, user=eesecure, pass=secure.

And hey presto, the Pi was connected to the Internet. At this point I was able to do all the usual stuff like running apt-get update and npm install -g node-red.

My next challenge was to try to get the Pi to connect  to a VPN. That’s for next episode.

Realtime information from my car (Episode 1)

I’ve been using the Torque Pro application with the OBDII port in my car for some time now and it’s performed perfectly. For people who don’t know what I’m talking about, Torque is an excellent application on Android to read the ODBII port in a car to retrieve useful information such as speed, revs per minute and much more. It’s served it’s purpose very well, but I got to thinking lately ‘how could I get realtime information to wherever I need it?’. Once I started thinking of that, it led onto ‘how could I track my car if it was stolen?’. I know you can buy this stuff off the internet, but I think the fun is in working out how to do it yourself. Not only that, if something goes wrong, you’re in a better position to fix it yourself, in my opinion. Plus, to a better extent, I can keep my information private, rather than sharing it wih a third party and all using open-source software.

So I had a big picture in mind

  • A system that can boot and configure itself without my interaction
  • A system that can start a 3G connection
  • A system that can automatically connect to the ODBII ports and start logging data
  • A system that can connect to a VPN for transferring data privately for further processing.

I don’t want to have to mess about setting up all this before I drive to work on morning, so I want all this to autonomously work.  I am not writing about this as a complete system at the moment, and is more of a journal of what I come across as I go about setting this. So there’ll eventually be a tutorial out the back of this series of posts, but I’m nowhere near there yet. As a phase two, I was thinking about having a touchscreen in there too, and a pi camera with face recog, but I need to get the basics done first.

I’m working on a bill of materials, and this is what I’ve got so far:

  • Raspberry Pi 3 (x2). One for the 3g connection and Node Red installation, and the other to control the ODBII flow. Wanted to use only one, but I’ve had a problem getting both the Pi 3 bluetooth and 3G connection to work on the same device, so I am taking the easy route for now
  • Huawei E1750 3G dongle for the 3G connection obvs.
  • Powered USB hub for the 3G dongle
  • USB Micro cables for linking the power
  • Internal bluetooth on one of the Raspberry Pi 3s
  • PAYG Sim card for connecting to internet
  • $4 Router for providing an access point in the car

Software-wise I’m think along the lines of:

  • Raspbian Jessie Lite (I can always install a GUI later if needed)
  • Node Red (with appropriate NPM libraries installed)
  • Sakis-3G for setting up the 3G connection
  • PyOBD-Pi for managing the OBDiI connection
  • Gammu for texting
  • OpenVPN for private data transfer.
  • MQTT for messaging

That’s about all I can think of at the moment, and I’m bound to add to this list. I will probably create some Arduino sensors such as  GPS, accelerometer, audio sensors and so on.

Anyway, stay tuned for episode two where I start piecing things together.

Now getting meaningful data from my garden sensors!

My father-in-law recently donated to me one of those thin plastic greenhouses, and although initially it was a bit flimsy, I managed to strengthen it a bit and safely store some plants and cuttings in there. At the same time I’d been trying to get some network-controlled garden lights working, but without much success.  I just couldn’t get the wireless function to work properly so I could control them from my mobile. The problem turned out to be a single stray line of code! I put a listening command in the wrong place, and effectively all my sensors stopped reporting to the base station. Anyway, managed to get that sorted, so at that point I remembered some two-year old moisture sensors I’d built, but never used in the garden where they were intended.

I reprogrammed the ATMEGA328 chip and burnt a 1mhz bootloader, stuck the chip back in the sensor and took it back outside. I fired up the base station again, turned on the sensor and lo-and-behold, I got some serial data over wireless to the base station which was running the awesome Node Red. I didn’t get too excited at this point because my previous attempts had faltered after a few hours. I came back to it a full two days later, and my sensor had successfully sent data for all that time every five minutes. Awesome!

I decided to brush off a bit of old Node Red work around recording sensor data, and link it to the work I was doing with the sensors. I used the new node-red-dashboard to present the information and there I had it; a sensor reporting live plant pot information every five minutes. I was well happy! Since then I’ve replicated my work and got four sensors working reliably with my base station with several more on the way. In the end, I got a nice-looking dashboard which gives me all the info I need. It was great to see the moisture levels change when the plant pots were watered.

Which takes me onto my task, automatic plant-pot watering without any involvement from me except topping up the water. I eventually want to scale up this to water barrels in the garden, feeding water to the various flower beds in the garden via a gravity-fed solenoid.

 

Greenhouse dashboard
Greenhouse dashboard

Apache Cordova, Ionic Framework and VS Code: The First Day

It wasn’t all that long ago that I was petrified of anything non-Microsoft. But all that changed when I bought my first Raspberry PI. A whole new world of Linux opened up to me and cheap experimentation with software and hardware I would never had dared to get involve with before. I don’t think twice now before cracking open a piece of old hardware now and replacing it with some new gubbins.

One area I haven’t looked at up until now is mobile phone development, namely Android. I remembered reading about something called Phonegap once, and that you could re-use your existing skills with HTML, CSS and Javascript. I decided to a look, and then I came across Apache Cordova. Slightly later I became aware of Ionic Framework too. Cordova supplies the underlying infrastucture on which your mobile app works, and Ionic  provides a really excellent framework for designing UIs.

On top of that I discovered VS Code, a great, free text editor with Intellisense from Microsoft. Also, helpfully, someone had released a Cordova plugin which would give me Intellisense for this development environment. Some Angular experience wouldn’t go amiss either if you’re just starting out.

To be honest, all this stuff was a bit of a ballache to install. You also need to install Java and Node.js and set PATH variables. Do I really need to install PATH variables any more? It is 2016 after all.

Anyway, I managed to get things set up and now I must say I am impressed with this VS Code, Cordova and Ionic arrangement and it was really satisfying to see my test address book app working natively on Android after issuing the command cordova build android. It sent my head spinning with ideas. Mobiles are so important these days, I use mine constantly for lots of different reasons. I’d avoided mobile app development up until now, but realised I couldn’t do that for much longer.

If you’re looking for a place to start mobile dev, and have some HTML, CSS and Javascript, then I can recommend this approach.

Apache Cordova: https://evothings.com/doc/build/cordova-install-windows.html

Ionic Framework: http://ionicframework.com/getting-started/

VS Code: https://code.visualstudio.com

Review: Samsung Gear VR – Real life is now sooo boring.

Rating: 5 out of 5

 

Obviously I’m being a bit facetious, but the Samsung Gear VR really is an awesome piece of kit. I’m now sold on the whole VR thing, and I’m gobsmacked by what a humble (Samsung Galaxy S6) phone can do (although it can get really hot doing so). Plug in a pair of earphones and it is a totally engrossing experience.

I’ve wanted to experience VR for a long time, probably since seeing the rendered (but in no-way-realtime) graphics in Lawnmower Man, and when I got my S6 I jumped at the chance of having a go. The goggles are well constructed and solid, and although I’ve read that the straps that go over the top of your head are uncomfortable, I can’t say the same for me. I can wear the goggles for a long time without any problems. They sit comfortably over your eyes and bridge of your nose, supported by the straps. I don’t think that you look like a complete numpty wearing these as they aren’t too voluminous, and they look quite futuristic. I believe these goggles will work with other Samsung phones, including the Note range, but in my opinion, the older S phones may struggle keeping up with the graphics requirements of VR. My S6, although not quite a cutting-edge phone anymore, is still a powerful phone and the frame rate drops sometimes when rendering very active 3D scenes, especially when using cardboard apps. The Oculus apps run much more smoothly than the cardboard ones and due to the much better framerate, the VR you experience is much more comfortable than in Cardboard apps. Often using the Cardboard apps, I’d end up feeling a bit sick and dizzy when the frame rate dropped considerably in some scenes. Anyway, I digress. The phone slots easily into the goggles and stays absolutely firmly in position all the way through a session.

So, donning the goggles for the first time, I was full of anticipation, and it definitely didn’t disappoint. The first thing I saw was the Oculus home page. Having never seen anything like this before, I actually shouted ‘OMG!!’ out loud several times. I can’t stand the phrase OMG usually because it’s totally overrused and annoying. But I couldn’t think of another phrase to convey the amazing visuals I was seeing, and this was just the Oculus home page! The homepage menu hovers in front of you at a tangible distance in one of the coolest rooms you’ve ever seen. I spent about 10 minutes in this home page menu room just looking around at the room. Awesome! My dog was getting pretty wound up at this stage as he could see I was really excited and moving about. He must have been thinking about why he couldn’t see the intruder I could, and it’s no fun getting jabbed in the nuts by your dog’s paws whilst you can’t see anything wearing a headset.

Another great experience is 360 degree photos and video. One of my favourite things to do now is to take photospheres with Google Camera and then look at them through the goggles and its fantastic. I have always been disappointed after taking photos and not being able to experience them in the same way as the real thing. But now you can, and its totally amazing to be inside your own photo and be able to look in any direction like you would in real life. Pardon the pun, but it adds a whole new dimension to viewing photos

Onto some of the games I have played. My current favourite is Smash Hit.

This is such a simple game, but absolutely awesome to play. The goal of the game is to progress through  the levels, throwing balls at little glass pyramids to add more balls to your arsenal whilst avoiding oor smashing obstacles in your path. The fact that this is in VR makes an otherwise simple game completely absorbing. If you miss smashing an obstacle in your current field of vision, you can just turn your head in its direction and take another pop at it. I would give this game 10/10 in its own right.

Another great game is Gunjack, which places you in a spacecraft turret above a planet, and you’re required to bring down alien drones with a variety of weapons. The environment feels pretty realistic, and you can sense the distance between yourself and the planet below. Also watching the drones explode all around you after shooting them down is great fun. Again it is totally absorbing.

In my opinion the Samsung Gear VR feels like a tantalising preview of what is to come in the next few years with higher spec or dedicated machines, and I feel it is a tad expensive, but to be honest, the experience is worth it. if you have a recent Samsung phone I urge you take the VR plunge!

NRF24L01, Ras Pi and ATMega in the garden

Recently I’ve been trying to create some network-controlled lights for the garden, which basically consist of a mason jar (image in the gallery below), a circuit board with an ATMEGA328P-PU chip and NRF24L01+ module.

I used this site to set up the Raspberry Pi part of my set up http://hack.lenotta.com/arduino-raspberry-pi-switching-light-with-nrf24l01/.

I also used the superb RF24Ethernet Arduino Library to create a TCP/IP stack on the ATMEGA chip:  http://tmrh20.github.io/RF24Ethernet.

I created a circuit board with the ATMEGA chip on it and the NRF24L01+ module, as well as a bright RGB LED, and uploaded the InteractiveServer.ino sketch that comes with the RF24Ethernet library and modified IP addresses to match the range that I needed. At the Raspberry Pi end, I attached the NRF24L01+ to the GPIO and built the environment that is discussed in the setup instructions contained in the RF24Ethernet site.

Whilst I tested at the desk in my house I successfully got HTTP requests flowing between the Raspberry Pi and ATMEGA chip via the RF module which was massively satisfying! I wanted to do this with WiFi via something like an ESP8266, but because I want to run my lights using 3XAA batteries (eventually charged by a small solar panel) they use far too much power. On the other hand the NRF module is very frugal. I’ve used it in some moisture sensors that I created a couple of years ago, and I’ve managed to keep them running for months on the same battery, admittedly just by polling information every 8 minutes. With the RF24Ethernet running (without turning the LED on) I got an idle time of around a week. That was good enough for me, because I should be able to get the lights recharged in less time than that via a solar panel.

Anyway at that point I could successfully turn on and off a light using HTTP just like you would do with a normal website. When I deployed the setup outside and I put the light jar down the bottom of the garden, the ping test I was running on my mobile stopped working. It turned out I had a couple of problems.

 PROBLEM 1
 I had some dodgy connections due to the dupont cables shifting when attached to the NRF module  via the Raspberry PI, I gave them a good wiggle and the signal came back to life. I think I am going to solder the NRF module directly into my design. I normally use dupont cables when dealing with the RPi, but I think I am going to come up with a board that fits on the gpio area of the Pi, with the NRF module soldered directly. As long as I solder correctly there’ll be no problems with connection. I’m pretty good at soldering these days. I think the secret is having a good soldering station and a hot enough temperature. In the meantime though, I soldered a 10uf on the NRF module (over the positive and negative headers) of the receiving and sending stations and I got much better communication between the modules. One of the stations is inside a glass jar covered in glass beads to hide the electronics and I still got a good reception.
PROBLEM 2
 As well as the first problem, I also discovered that the NRF module appears to be very directional. I guess I could have discovered this earlier by reading a blog post, but it was really satisfying to discover this purely by my own efforts. Anyway, to cut a long story short, I just ensured the base station module was correctly pointing towards the lightjar and the antenna on the light jar was oriented towards the base station and hey presto I now have a solid connection between the Ras Pi and Lightjar. What’s nice is that I’m able to use Node-Red to ping the lightjar every four minutes and then I’m using Node-Red-Contrib-UI to keep track of the pings with a graph and gauge.
I am surprised by the apparently directional nature of the NRF module and  I may be completely wrong on this, but it’s what my experience of the device showed me during testing. When I walked with my light jar either side of where I suspected the beam to be transmitting, the ping stopped working in the SSH window I had open on my phone. I could also see the TTL time increasing or decreasing depending on whether or not the radio was facing towards or away from the base station. Like I say, it was cool to discover this myself, and it will now at least inform how I do the rest of my light jars in the garden. It probably looked very strange to the neighbours, me walking down the garden with a jar in my hand and a phone in the other!
I’ve had my set up running for about  a week now and it’s been pretty solid. I ping my might jar every 4 minutes, and the connection has been great. I think once you’ve got things set up correctly then the NRF modules with RF24 Ethernet are a reliable combination. The mason jars have performed very well too and have kept my electronics nice and dry.
I’ve started creating my second jar, and have run into problems again, but it looks like different problems! I’ve got this running once so I am sure I can do it again! It’s all part of the journey.

Wifi-enabled Raspberry Pi Zero Up and Running in 2 minutes with Node-Red!

I am truly impressed with the Zero. Earlier this evening I plugged in  a SD card image with Raspbian and Node-red installed (built on Raspberry Pi B+) and it booted up first time with no problems. I SSHed into the Zero, started Node-red and that was it! So, my first day with the Zero has been fantastic! What an amazing piece of engineering at a tiny price (if you’re talking about the unit itself). I see a seriously RPi-Zeroed time coming in my life. The applications are endless.