ESP32 powered webcam for 7 pounds

esp32-cam.PNG

In my fingers above you can see something rather amazing. It’s an ESP32 powered webcam and it is priced at a stupidly low level. Mine arrived earlier this week and I’ve found a splendid howto that gets you started. You’ll need a serial interface to program the camera as it doesn’t have a usb connection. I used the one I got with some Arduino Pro-minis a while back. A couple of tips:

  • make sure you update to the latest version of the ESP32 board. The older camera sample will not compile.

  • the device can be a bit picky about power supplies. Mine gave “brownout” warnings for a while before I connected the 5V input to a slightly beefier supply than the 3.3V I used to program it

The camera serves up a website with a wealth of controls that you can use to change the image quality. You can use it to grab stills or watch a video stream. It even supports facial recognition and it has a micro-SD slot for saving stuff to. Amazing.

2019-04-18.png

For the price you really should get one of these and have a play. I’ve been looking for a quick way to get pictures into Azure for training image recognition. I think I may have just found it.

Crippled Hexabot

Ages ago (well, four years) I made a hexabot from a kit. Today I thought I’d get him out with a view of adding some sensors and an ESP32 to make him a bit more autonomous. He was a bit lame. Two of his servos had stopped moving. Fortunately I had some spares and so I set about getting him walking again.

It didn’t go well. I broke a replacement servo finding its mid point and fitted the second one upside down. Twice. I think that a few hours of gardening has destroyed my ability to work with electronics.

However, I think he is now back to his sprightly best. I’ve ordered a camera pan and tilt (around 3.50 with servos) and a distance sensor with pan mechanism (also around 3.50) from AliExpress. Looking forward to them arriving.

Photographing circuits

46590782695_965c886419_k.jpg

I’m writing some embedded development content and having great fun doing it. I need to take pictures of the hardware during construction. In the past I’d be reaching for a proper camera, but nowadays I use the camera on my phone. The quality is very good and a tiny phone camera has a depth of field that makes sure that everything in the picture is nice and sharp. It’s also rather nice that the pictures on the phone are sent straight up to my Onedrive camera roll where I can just pull them out and drop them into the document I’m writing.

Air Quality Fun at Leeds Sharp

Some of the audience at the start. Note my lovely Surface Go running the whole thing…

Some of the audience at the start. Note my lovely Surface Go running the whole thing…

Had a great time at the Leeds Sharp meetup tonight. I was there to talk about Air Quality, Azure Functions and Lora. With a guest appearance of my Air Quality top hat. I’m pleased to be able to report that every demo worked. Even the impromptu one that I wasn’t expecting to…If you want a look at the slide deck you can find it here.

One of the lovely things about the night was that the first two folks that I saw at the venue were a couple of Hull alumni, Joshua and Andrew . They were there to make a video of the event. So they did. It’s really good, they’ve caught the presentation content along with some shots of me prowling around looking nervous. I think I’ll hire them for all my events. They’ve put the video on YouTube, you can find it below.

Simple Bluetooth BLE between ESP32 devices

46106418305_9d9af13253_k.jpg

There are lots of things in life that are supposed to be difficult. One of them is getting Bluetooth to work between devices. However, this is now not the case. Because I can do it.

It’s not quite a simple as you might expect though, the BLE server and client examples for the ESP32 devices distribution don’t work straight out of the box (they really should) because they use different service and characteristic ids and (and this is the tricky one folks) the device name for the server is more than three characters long (which for some reason stops the client from recognising it).

Anyhoo, to make things really useful for you I’ve slightly fettled the samples and dropped them on GitHub for you to just grab and go. They make it super-easy to send messages from one ESP32 to the other.

You can find the library here: https://github.com/CrazyRobMiles/SimpleESP32BluetoothBLE

ESP32 Bluetooth BLE to Windows 10 Universal Apps

BLE Windows 10.png

So I’ve got this lovely little M5Stack device with an ESP32 processor on it and it is supposed to support Bluetooth BLE. So I thought I’d see if it did. So fired up the example Bluetooth BLE program in the Arduino SDK and then I fired up the Bluetooth sample from the Windows-Universal-Samples and tried to get them to connect.

And they just did. Astonishing. In no time at all I was sending messages from the PC to the M5Stack, and with a bit of fiddling I managed to get data values going the other way as well. I find this amazing and wonderful. Previous attempts to get Bluetooth working like this have always been fairly horrid and fraught. With this I just hit the pair button inside the app on Windows 10, accept a security prompt and then I’m sending packets of data backwards and forwards. I’m definitely going to build something based on this,

Adventures in Colour at the Connected Humber Hardware Group

40471170163_79f0259417_k.jpg

We had a great time at the Connected Humber Hardware group meetup tonight. We talked air quality, transistor design, top hats (of course) and making colours.

There’s nothing like playing with something to build your understanding of what is happening. Jay has been making remote controlled lights and has built a remote controlled a three colour led. Individual colours worked fine, but mixing them didn’t give the colours that we were expecting. This turned out to be because the individual red, green and blue light sources in the led were all very different in brightness. However after a bit of experimentation with series resistors he managed to get a reasonably balanced result, as you can see above. What’s more this serves as a lovely illustration of how primary colours can be combined to make others.

Great fun. If you want to take part (and why wouldn’t you), our next meeting is on the 3rd of April at 6:00. You can find our more about our meetups here.

BME280 Power Fun

bme280.PNG

Sometimes the old solutions are the best. In this case the solution is “Turn it off and then on again”. I’m using a BME280 temperature, pressure and humidity sensor in the air quality monitor that I’m building. It works well, except sometimes, when it refuses to say hello when it starts up.

This has caused a certain amount of head-scratching. However, after a while I worked out that it only misbehaved after I had downloaded some code into the device. It’s as if it doesn’t like being woken up twice once it has been powered up.

Now if it gets stuck I just unplug the device and plug it back in. It’s something to be born in mind when you can’t get something to work.

I have a special category in my work (particularly with hardware) called “Things you do to make it work but you don’t know why”. This is another one.

Neopixel leds and power supply fun

When you try to make hardware it sometimes turns out that every bit is the difficult bit. Like today for example. Yesterday my latest Neopixel lights arrived. They are on a strip of 8x32 pixels on a flexible pcb. It’s awesome, with power demands that I’m not that happy thinking about. The plan is to do something vaguely “Steam Punk” with them, perhaps involving my recently purchased top hat.

To celebrate I broke out my 10 amp 5 volt power supply. The one that I’ve not dared use yet. Having checked that the power supply produced a vaguely sensible voltage (around 5.5 volts) I tested the Wemos I was going to use (won’t get caught like that again) wired it all together and fired it up.This part of the project should have been the easy bit.

It didn’t work.

In a panic I disconnected the power supply, thinking that I might have wired the positive and negative wires the wrong way round (which is a good way to destroy anything). And suddenly it started working.

It turns out that this is completely normal behaviour. The problem is in the way that the NeoPixels detect their signals. They regard anything above two thirds of their power supply voltage as “true”. If the power supply is 5 volts two thirds of that is around 3.3 volts, which is exactly what the Wemos device produces on its output pins. Happy days.

However, if the power supply voltage is higher than 5 volts the voltage level needed to send a message to the NeoPixels becomes higher than the 3.3 volts that I get from the Wemos and so the communication starts to fail.

So it’s all down to my power supply being too powerful. There are two possible solutions. The first is to use a level converter to boost the signal from the Wemos to 5 volts so that the pixels will react to it. The second is to drop the power supply voltage down to 5 volts so that the maths is in my favour. Ongoing……

Storing Json Configuration Information in devices

I’m a big fan of Json. It is a great way of expressing values in a meaningful way. I’m going to use it to store settings information in our Air Quality sensors. This will make it easy to understand, and extensible. It turns out that it is also very easy to do. I started with an online json editor at https://jsoneditoronline.org/ That helped me come up with this:

{
  "ver":1,
  "wifi": [
    {"ssid":"ssid", "password":"pass"},
    {"ssid":"", "password":""},
    {"ssid":"", "password":""},
    {"ssid":"", "password":""},
    {"ssid":"", "password":""}    
    ],
  "mqtt":{
    "mqttID":"robert01",
    "mqttHost":"mqtt.connectedhumber.org",
    "mqttUser":"connectedHumber",
    "mqttPassword":"pass",
    "mqttPublish":"airquality/data",
    "mqttSubscribe":"airquality/commands",
    "mqttIntervalSecs":60,
    "mqttRetrySecs":20
  },
  "node":{
    "nodeID":"sensor01",
    "noOfPixels":12,
    "pixelColour":{"r":0,"g":255,"b":0},
    "airqSensorType":1,
    "airQLowLimit":1,
    "airqLowWarnLimit":2,
      "airqMidWarnLimit":3,
      "airqHighWarnLimit":4,
      "airQHighAlertLimit":5
  }
}

The json design provides all the information that a sensor needs, including the WiFi settings for 5 different networks. MQTT connection settings and the limits for my warning displays on the coloured pixel.

Next, I needed the C++ to convert the Json into settings that my code inside the device can use to load and store the values when the device runs. It turns out that the Arduino json library has an awesome web page where you can just paste your json and out drops C++ to read and write the values.

I just went to https://arduinojson.org/v5/assistant/ , dropped my Json design into the pate and out came the code. I’ve got to map the settings values onto the variables I’m using in the program, but that is much easier than writing everything from scratch.

This won’t work with the very small Arduino devices because they haven’t really got enough memory to run such large libraries. However, if you’re using an esp8266 or esp32 this really is an easy way to manage internal settings. I’m going to store the json itself using the internal filestore. I’ll post how to do this in a little while.

Porchlight 2.0

46378553012_11f91dea28_z.jpg

Well, Porchlight 1.0 fell down sometime last night. But no damage done. I’ve switched to a stronger type of adhesive strip and also wedged the light strip into place. I’ve also made an internal version of the lights so that I can test my displays without having to deploy them on the front of the house, which seems like a good idea to me. Now that I’m a bit happier with the power supply I’ve changed to a version of the code that turns on a lot more lights at once, for extra brightness.

Christmas Lights Taking Shape

lightRope.PNG

Every year I have a plan to make some Christmas lights using Neopixel leds. This year I’ve actually got as far as buying he leds and a power supply unit. Today I spent a happy half hour wiring everything together and a less happy half hour finding out that if you put a series resistor in the data line to the leds (as you are advised to on the web) they don’t work reliably.

Today’s hard won lesson: it’s not always your software that’s at fault. Sometimes the hardware can go wrong too. Once I’ve got the lights working I’ll post a video on here and the code on GitHub. It’s turning out to be quite fun.

Using Serial1 with the Azure IoT Devkit

44356419010_f4bcb68f9f_z.jpg

A while back I posted about changes you could make to the Azure IoT DevKit library so that your programs can use the second serial port of the device to talk to things like GPS receivers and Air Quality sensors (a particular interest of mine).

At the time I suggested that this could be fixed by adding the creation of a second serial port to the SDK. I’ve just heard back from the team and this is not going to be done. Instead we can create a Serial instance when we need one, which saves resources.

If you want to use Serial1 with your Azure IoT device you can add the following statement to your program.

UARTClass Serial1(UART_1);

You can then use Serial1 in exactly the same way as you use Serial. I’ve put a sample program on GitHub that shows how this works.