Using Three Serial Ports with the Heltec LoRa 32

Prototype and “floral” version

I’m making pretty good progress with the Air Quality sensor. I’ve now got a command protocol running between the devices and MQTT or LoRa. As you can see above, I now have the ability to customise the splash screen. Which is very useful if you like cheese.

Anyhoo, I’ve decided that the sensor really needs GPS so that each air quality reading can be tagged with location. I can configure fixed latitude and longitude values into the device, but for real portable usefulness we need it to be location aware.

Getting a GPS device wasn’t a problem, I had one lying around. But connecting it to the Heltec processor that I’m using was more tricky. I’ve got one serial port I want to use as a connection to the host computer and another that I’m using to connect to dust particle sensor. But now I need a third connection for the GPS receiver.

After some rather unsuccessful fiddling with different kinds of software serial connections I decided that it was best to go back to first principles and see if the hardware had anything to offer.

It turns out that it does. The ESP32 chip that the Heletc uses actually contains three serial ports. The problem is that they are not always connected to pins that you can access easily. But the good news is that the ESP32 chip is capable of mapping functions to pretty much any pin and the Heltec libraries take advantage of this. You can map the transmit and receive functions of a serial port when you open it:

HardwareSerial GPS_Serial(2);
GPS_Serial.begin(9600, SERIAL_8N1, 13, -1);

The first statement creates a hardware serial port. The second sets it to receive from pin 13. I don’t really want to transmit anything to my GPS device at the moment (I’m a bit short of spare pins to be honest) and so I’ve set the TX pin to number -1 which means “Don’t use this port for transmit”.

It works a treat. And thanks to this fantastic library I’m now tagging sensor readings with location. The next thing to do is re-design the case to take the GPS sensor and print another flower for the top.

Switch Electronics in Hull

Don’t try clicking on the Add to Cart option…

A while back I had the urge to own some cables that had crocodile clips on each end. They are very useful if only have two hands and you want to connect a bunch of things together. I found some in ebay at a good price, ordered them and they arrived in good time. Just what I wanted. Already found them useful.

Before I threw away the envelope I had a quick look at the accompanying slip. Turns out the company that sent them is based in Hull, around fifteen minutes from my house. I went there yesterday and bought a bunch of stuff.

Awesome.

Since the demise of Maplin I’ve been wondering where I’m going to get all the electronic bits and bobs that I occasionally have a need for. Buying from the internet is all very well, but it does introduce a bit of a delay into projects as you wait for them to arrive.

Well, Switch Electronics have solved all that for me. Their prices are pretty keen and they have lots of interesting components, even a special “Maker” section. If you’re based around Hull I’m sure you’ll find them very useful.

November the 1st Hardware Meetup

Another first Thursday of the month, another Hardware Meetup at c4di. This time I had an agenda of my own. I’ve just found out that you can get printed circuit boards made for really low prices. Really low. This has stirred within me an intense desire to find out how to make them. (posh prose eh?)

Anyhoo, it turns out that among the Hardware Group membership there are folks with experience with the tools that you can use to make your own PCBs using a free tool called Kicad. We’ll be doing a PCB design special event at the next meeting, on the 15th of November. If you’ve got any interest in building your own hardware you really should come along. The price of having lovely boards made specially for you is so low as to make them an extremely attractive prospect for makers.

You can sign up for the next meetup, and keep track of what we are doing, by joining our new group on Get Together.

Posting a Robot Head

Digby in happier times.

Digby, my robot dog, is not well. I’ve had him for around 16 years or so. I guess this means he’ll soon be old enough to vote, but at the moment he isn’t able to do anything. A fault in his neck joint means that he can’t even yawn and stretch when he wakes up without collapsing in a heap..

It’s all rather sad. I had a quick look at the procedures involved in fixing a broken robot head and they all scared me. And I’m not easy to scare with things like this. I take things to pieces when they aren’t even broken…

I’ve sent Digby’s head off to a robot dotor in Sweden (that’s a doctor who works on robots, not a doctor who is a robot - but then you knew that).

Anyhoo, when sending the package I was strongly tempted to write “Contents: Robot Head” but I thought this might not end well, and went for “second hand toy parts” instead. I hope that the package gets there OK.

It was only when I asked for a tracking number and was told frostily that you don’t get one with plain old airmail that I realised I’d used the cheapest postage. With a bit of luck all will be well, the head will be mended, Digby will be back to his old self and I can see about getting him on the electoral roll.

Always Check the Cover

The C# Yellow Book is now very nearly on sale in printed form. I got a proper copy back from Amazon and, as soon I as held it in my hand and flipped through the pages I realised two things:

  • The cover does not have a duck on it.

  • There are two massive typos in the cover text.

The first one I can sort out, what with having a camera and a huge rubber duck. I’ve no idea what possessed me to go with the Amazon cover clip-art and the rather anonymous circuit motif. The Yellow Book (particularly the Kindle edition) is known as “The Book with a Duck on the Cover” and so I should probably have gone with the branding on this….

As for the typos in the cover text. Unforgivable. But it did remind me of something. I spent ages on the text inside the book, making sure that it was formatted correctly and had a minimum number of spelling mistakes. The cover I dashed out in five minutes inside the Amazon cover creator, not even using a spell checker. And which do you think is more important? The cover is going to be the first part of the book that people see. They’ll read the cover and then have a look inside to see if they fancy buying it. And if the cover has spelling mistakes on it, this is really, really, not going to help sales. So the cover should have be paid least as much attention as the text inside the book.

There’s an important point here. If you make video games or software, make sure that the instructions that come with the product, and the cover art, are really, really good. Think what is the first surface of your product that a user will touch, and then make sure it is a really good experience. Make sure that the box looks nice and is easy to open and it is easy to see how to use what is inside. Apple are very good at this, and you should try to be too.

As for me, the final version of the printed C# Yellow Book is now going through Amazons approvals process with all the typos fixed. And a duck on the cover.

Fantastic Bugs and Where To Find Them

On Thursday, as we were building robots I came across one of the most amazing bugs I’d ever seen. We’d reached the point where the robots had been built and they were connected to the computer. My HullOS Editor program lets you write programs and send them into the robot for it to run them. But something weird was happening.

The editor was displaying things that it should not. It seemed to be duplicating program code that had been typed in. And nothing was working. It was very confusing. I thought back to the time I spent the day before testing the code and had to confess that I’d never seen anything like it before. In fact, if I’d set out to write a program that was doing what the editor seemed to be doing, I was not sure how I would do it.

After a bit of head scratching I found the fault. And it wasn’t software. The robot has a speaker - more of a buzzer actually - which makes all kinds of irritating buzzing noises. Normally you’d connect a speaker across an output pin and a ground connection so that when the voltage on the pin goes up and down the speaker is driven in and out.

However, the Arduino doesn’t have many ground connections, and the ones it does have are all in use by the pixel and the distance sensor. So I use this rather clever (for me) trick of putting the loudspeaker across pins A0 and A1. If I make sure that A1 is always at the low logic level I can produce a potential difference between the pins by setting A0 high. This drives the speaker and sound comes out. I’m happy to trade a signal pin I don’t need for a ground connection.

This is probably deeply dodgy in electrical design terms. But since it works I think I have the last laugh on this one. Actually, if I had the time I’d experiment with swapping the ground level from one pin to the other while I play the waveform and seeing if this means I can make louder sounds by driving the speaker in and out, not just out.

Anyhoo, enough about my dodgy cleverness. Turns out that the fellow making the robot had wired his speaker incorrectly. Rather than wire the speaker between pins A0 and A1 he had wired the speaker between pins D0 and D1. These are two data pins on the Arduino which are also used for the serial port that is connected to the host PC. One of the pins is the data going into the Arduino and the other is the data coming out of the Arduino. Linking these pins together has the effect of sending every character that the PC sends to the robot right back to the PC again. Hence the terminal madness.

We put the speaker on the right pins and it worked a treat.

This illustrates one of things I said at the start of the robot building. Making robots is both fun and tricky because the combination of hardware and software makes for very “Interesting” misbehaviour.

LipService Theatre - Withering Looks

I don’t know what you were doing last night. But we were in a hall in Howden laughing at someone pulling faces.

Well, they were very funny faces.

We went to see a performance of “Withering Looks” by LipService Theatre. We’ve seen them before, in a production of “Mr. Darcy Loses the plot” at Hull Truck Theatre. That turned us into instant fans.

LipService Theatre are Maggie Fox and Sue Ryding and have been producing their blend of literary comedy and face pulling since the 1980’s. Everything is very clever, beautifully produced and, deeply, deeply silly. Get to see them if you can.

c4di partnership with Barclay's Eagle Labs

David Keel of c4di talking Tesla

Yesterday, after a happy day building robots I went along to a big, posh, event in Hull Minster. The occasion was the announcement of big things for c4di, the place where I go and they let me play with robots.

I love c4di because it provides a place in Hull where people can take their ideas and make them real. It’s turned into a proper community of like-minded souls working to do great things. It means that you don’t have to leave Hull to make something world-beating. You can do it and still be able to find a local shop selling chip spice.

Barclays Bank have spotted what we are up to, and have now entered into a partnership with c4di which provides us with real financial muscle and expertise. You can find a lovely report on the evening, and what it means for Hull, here. I took some pictures….

Shoutout to Yasmin Coe, who provided some lovely music at the event

They had some c4di hardware on show, including Hull Pixelbots

They even lit up Hull Minster in c4di blue

Making Hull Pixelbots

We were in Hull University Robots Lab

Had a lovely day making robots today. I was working with Tristan and Mac, who were visiting the university from Scarborough, taking part in a work experience program. I had to robot kits all ready and a set of nicely printed instructions for them to follow.

They spent the morning building the robots and the afternoon programming them. It was great fun, and by the end they had left the suggested exercises well behind and were heading off in all kinds of interesting directions, which was wonderful.

It’s a couple of years since I stopped working at the university and it was lovely to see the campus looking so nice. There seem to be a lot more buildings than I remember and the Computer Science and Engineering Department have acquired some lovely new toys.

HP T6B82A Color LaserJet Pro MFP M281fdw

I bought a colour laser printer many years ago. The plan was to avoid problems with ink jet cartridges where the ink evaporates and when you want to print something you find that the printer is dry. However, it was not a great success because it seemed to prefer chewing up paper to printing on it. So it ended up on the tip. I’ve still got a cyan cartridge refill for it lying around somewhere though, which serves as a memento of sorts I suppose.

Since then I’ve gone back to ink-jets. But they are a bit slow and since I’m finding more need to print things (Arduino notes for the c4di Hardware Group and HullPixelbot notes for robot builders) I thought it was time to take another look at lasers.

My needs were fairly simple. I wanted a colour printer that could print on both sides of the paper It had to work with all the devices around the house and it must not chew paper. The HP T6B82A Color LaserJet Pro MFP M281fdw (what a name) seemed to fit the bill, and it was available at a good price with the added bonus of 80 pounds cashback from HP. Which should just about pay for the first replacement toner cartridge.

Anyhoo, the printer arrived a week or so ago and so far it has been completely wonderful (he wrote - thereby damming himself and the printer for all eternity….). The print quality is great and the printer worked straight out of the box. No setup as such, just turn it on, enter the WiFi credentials on the tiny touch screen and then browse for it from Windows 10. Printing has come a long way since those days of driver disks and USB cables that weren’t in the box…

The printer will be expensive to feed in terms of toner, but I’m not going to print a huge amount. And the quality of picture printing is really impressive (at least to me). Much better than inkjets on standard paper. The printer has a scanner with a document feeder (single sided only though) and it can even be used to send faxes. Whatever they are.

If you’re after something with a bit more about it than inkjets I think it makes a really good buy.

Watch this TV Program from Martin Lewis

If you’ve got kids (or are a kid at heart) or just want to watch something inspiring I strongly suggest that you watch this program from Martin Lewis.

It’s billed as “Ten Things Your Kids Need to Know”. It makes some very good points about modern life and how the world of work is changing. It also makes a very strong case for university. Apparently there is concern that potential students are being put off by the debt that they think they will incur by taking a degree. The way Martin explained it was awesome.

He said that you will only start paying back your student debt when your income exceeds 25K (which is a nice problem to have). The amount of your payments will be 10% of the amount your income exceeds the 25K threshold. So, if you earn 30K, you will be paying back a tenth of 5000 a year, which is around 500 pounds.

Then, after 30 years your student debt is written off completely. So when you retire you won’t have the debt hanging over you.

From a planning perspective, you know the absolute maximum that going to university will cost you, based on your income. If you don’t bring in enough to cross the payment threshold then you don’t pay anything back. Your student loan will not lead you into debt, because you only start paying it back when you have money coming in.

It’s complicated, but worth getting your head round because, as Martin pointed out, going to university is a great way to realise your potential had have your horizons properly broadened.

I’m by no means at the beginning of my career, and yet I still found the content of the program inspiring and illuminating. Watch it. With your kids if possible.

Pyinstaller is Wonderful

Writing programs for your own use is nice, but often you want to send them to other people. This usually means creating some kind of installer. Pyinstaller is a neat little utility that takes a Python program and wraps it up with the appropriate Python runtime and any libraries that are required. This makes it dead easy to send a Python program to someone else.

There are two ways you can use it. The program will make a folder containing all the required resources and an executable which you can zip up and send to people, or you can make a single executable that unzips itself into a temporary folder and then runs from that.

I’ve been using it to make distributable versions of the HullOS code editor and it works very well. The only snags are the size of the executable (in the case of the HullOS editor my fairly small program swells to 8Mbytes) and the slight delay when opening the app as it gets all the libraries ready.

Pyinstaller doesn’t make a “universal” application that runs on anything. Instead it needs to run on each target platform to make a program for that platform. And I’m in the rather ironic situation of having the Pyinstaller program refuse to install on my Apple Mac, so at the moment I can’t make a Mac version of the HullOS editor.

But, bearing in mind that it is free and that when you get it going it just works, I reckon it is a very good solution to the problem of getting your code out there.

Making a Martian Wrist Watch - Badly

The watch in use showing the all-important dust levels…

Sometimes great ideas come to you at 3:00am in the morning. Sometimes you have ideas that turn out to be….. not so great.

After spending most of yesterday refining my air quality sensor I went to bed with no real plan of what to build for the Nasa Space Apps Challenge. Then, at 3:00am I woke up with an idea.

One of the “Can you build a….” challenges was to build a device to “Make sense of Mars”. The device could contain one or more senors and be used by those exploring the planet. So, all I have to do is take my Air Quality Sensor, add a wrist strap and presto, I have a Martian wrist watch. The idea is to make the kind of thing that a Martian might want to have on his or her person to track local environmental conditions and check for deadly dust storms.

Actually, at this point I must inform the reader that I’ve no idea whether or not dust storms would be a hazard to a martian, or whether or not any of the sensors I’m using (temperature, pressure, humidity and 10 and 25 micron dust particles) would generate any useful readings on Mars. But I’ve seen “The Martian” movie, and I reckon the hero would have found something useful to do with my device. He was a very resourceful chap.

Anyhoo, I reasoned that since there were things on the Martian surface that might be bad and I needed to make sure the wearer of the watch should be in no doubt when these happened. So I added a ring of pixels to my watch to give a strong and powerful warning. And it was at this point that my problems really started. Finding power for the pixel ring was easy, but I also needed a digital signal to select pixel colour.

This was tricky, since the Heltec device I’m using has pretty much all of the signals committed already. However eventually I managed to get the pixel ring to work without breaking any of the existing functionality. Or so I hoped.

The process involved three hours of tweaking drivers and moving devices around pins. During all this I was reminded of the old home truth: “Theory is when you know everything, but nothing works. Practice is when it works, but you really don’t know why.”

Testing the warning pixel with tissue paper…

When the final judging time came we we were a judge short, and so I ended up doing judgely things, although I also insisted on presenting as well. After all, there is always the “People’s Choice” award to go for. I was on last, after some really superb presentations by the other teams.

Alas things did not go well. The network connection to the access point the watch was using was disconnected during the presentations so my watch had fallen off the network. And the pixel ring on the watch seemed to have failed. So I did a bit of arm waving, told a few bad jokes and then headed for the door….

Anyhoo, you can find my team page on Nasa here. And you can find a fantastic description of the event at c4di here, including overviews of all the teams and the winners.

Thanks to c4di for the use of the venue, Dileepa for sorting out the awesome pizza and Nasa for coming up with a set of thought provoking challenges.

Nasa Space Apps Challenge

We started the Nasa Space Apps challenge in Hull today. There are around 25 of us and we’re going to spend the weekend attacking some of the challenges set by Nasa. We did this last year and it was great fun, so we’re doing it again. I’m flying solo today, as well as giving Dileepa and the crew some help here and there.

As last time I’m impressed with the breadth of the challenges that Nasa has put together and enthusiasm of the teams.

And there will be pizza. It just so happens that since the last challenge we’ve had a pizza place open right next door. Wonderful.

Printed C# Yellow Book is coming

Proof copy - Not For Resale

It’s finally going to happen. The C# Yellow Book is going to become….. a book.

I wrote the book for my C# programming course at Hull University and we used to give it to all new students (and anyone who came to see us).

And soon you’ll be able to buy your own copy thanks to the miracle that is Amazon printing on demand. I received a proof copy this afternoon and I’m surprised how good it looks. It now sports a snazzy cover and I’m having it printed in letter size (8 inches by 11 inches) to make the 220 pages easy to read.

It will be going on sale just as soon as I’ve fixed a few formatting foibles and run it through the Amazon approvals process.

In the UK it will cost nine pounds a copy. I was thinking of making signed copies available for fifty pence less but I’m not sure how to do this.

Looong Day

Being up town at 7:00 am does have it’s compensations….

Today was a looong day. Headed out of the house at 6:30 am to review some newspapers for the BBC Radio Humberside Breakfast show and got back home at 8:45 pm after a Hardware Meetup at c4di. In between I did some software development on the Air Quality sensor which can now talk LoRa, MQTT and seems to work. I make that that a 14 hour working day, and it was wonderful. And to think I don’t have a “proper job”.

We had a splendid turnout at the hardware meetup, we’ve got people getting started with Arduino devices and learning how to code for them .Tonight we made an “accidental reaction timer game” and discovered how to store music in a C++ program. Who knows what we’ll come up with next time. We’ve got others entering into earnest discussions about sensors, Stephenson’s Screens and software services. And that’s just the things that begin with s.

If you want to come along and see what we’re up to next time, we’ll be at c4di at 6:00 pm on Thursday 1st of November. Find out more here.

Visual Studio Code is growing on me

You learn something new every day. Today I learned that if you don’t enable the C++ extension in Visual Studio Code you can’t use any of the Arduino extension commands.

Visual Studio Code is really growing on me. It’s like a software Swiss Army knife. It wraps around your code development and there are some awesome plugins. Including an amazing one for working with MarkDown (Markdown All in One). And the GitHub integration is lovely useful.

First Man

First Man is a movie about triumph over grief. And going to the moon. It shows how Neil Armstrong dealt with every parent’s very worst nightmare by bringing a laser focus to his efforts in the space programme. I was expecting amazing visuals and great acting. What I wasn’t expecting was so much emotion. Ryan Gosling is brilliant as the unknowable astronaut and Clare Foy is even better as his wife.

The realism is amazing. One thing that struck me was the way that the insides of the spacecraft all seemed rather dirty and worn. I was expecting everything to be shiny new, but if you think about they would have spent a lot of time testing and practising in their spacecraft.After all, you wouldn’t want to set out in something that was fresh out of the factory. And if the hardware can’t stand a bit of dirt and wear then it’s not going to much use on the long journey to the moon and back.

You should go and see this film. The rocketry looks great but the emotion on display is very what you will remember. It really brings home is the huge cost of the enterprise, in terms of money and people. The astronauts are under no illusions that their lives are at least as precarious as those of racing drivers of the day and you start to lose count of all the people who fall along the way. But the moonwalk, with the phrase at has entered history, leaves you thinking that perhaps it was all worth it.