Meason Firmware Development

I have been quiet on the blog as I focused on becoming an P.E. in Electrical Engineering.   Now that  I am an Professional Engineer I have more time to focus on the measons project (STM32 Sensor Nodes project).

Since my last post I received the PCB’s and they checked out well.  The only issue is a button which has the wrong pins going to the footprint (something that is fairly easy to fix electrically). My primary focus has been on firmware development for the Measons.

As a recap, the project that I have named Measons is a primarily embedded project with the aim to detect common household failures and to send a text message/email when a failure is detected.  Common household failures could be a leaking toilet, water heater, AC drip tray, AC/Heater failure, washing machine leak and stove monitoring.  There are two types of measons, a measuring meason and a listening meason, which saves the messages from the network and reports it to a PC. A key feature of this project is that all measons have exactly the same firmware, the only difference between measons is the eeprom that is read on startup.

During these few months I have implemented reading eeprom configuration on startup, and having one meason report temperature measurements to another, which then is saved into a CSV using a small python program.  Looking at the data I can clearly tell when the AC turns on and off, and the temperature of my router and cable modem throughout the day.  I ran this temperature gathering experiment for over a month with excellent reliability.

A key problem I discovered was that license that AC6 tools provides on their example code forbids the distribution of the AC6 generated files.  Based on this license restriction and the frustration of not being in control of ones own development environment, I switched to using makefiles to generate source code in Eclipse Mars.  The linker file was generated from scratch and OpenOCD is behaving as it did in the AC6 System Workbench.  This change forced me to learn how makefiles and linker scripts work to a greater level of detail, which is great for my line of work.

Currently I am working on a bootloader for the measons which will allow the main application to be updated wirelessly, and for updates to be sent to the entire network.  Currently that bootloader works for a direct serial connection, but it needs added support for reading packets over the RF connection.  I expect for this to be competed within a weeks time (it sure can take a while to do firmware development when you have a full time job!).

Happy Holidays,




STM32 Nucleo Expansion Board Recieved!

This is just a quick post showing the newly arrived PCB’s.  I have only found a few errors in the board where the STM32 Nucleo Expansion port didn’t have some signals that I assumed.  Luckily I added enough 0 ohm resistors and work arounds so that it won’t be a problem.  (Latest schematics on Github show the changes in the Develop Branch).  I discovered the problem when adding OneWire support for the DS18B20 temperature sensor.  Once I get all of the other sensor ports working I’ll flush out any other unexpected behavior and keep the schematics updated as I progress.




Bottom Side

I got 10 of these boards for about $20 so it was a really good deal. These boards were made in Kicad and the designs and all source code is available on github as explained in this post.

After attending Embedded Systems Conference this past week, I’ve got quite a few new ideas to making these sensor nodes firmware more robust, with licensing terms that will allow me to use the software I create in open source projects as well as closed source.


Teensy 3.1: Adding mouse scrolling support for Linux

Logitech wireless keyboard + Teensy 3.1 + USB Host chip

Logitech wireless keyboard + Teensy 3.1 + USB Host chip

I recently started a project with a Teensy 3.1 and USB Host Shield, I dub it my Keyboard/Mouse Macroizer.  The objective was pretty simple: Record and Playback all of the actions one typically does with a keyboard and mouse.  This is fairly unique since it can record not only keyboard actions, but mouse actions too.  Currently I have two of them and they are my default keyboard and mouse both at home and at work.

LCD + 3d printed case

LCD + 3d printed case

Today I’ll just be talking about some modifications needed to the default Teensyduino 1.18 to add the necessary support for mice.  Apparently there is a bug in the linux driver for mice support, that causes the scrolling action on an absolute mouse, to not be processed by linux.  One day I may track it down, but for now, my work a round is to add a second mouse to the USB descriptors that the Teensy passes the OS when it begins the enumeration process.

Just so everyone knows, I’m using Eclipse as my IDE for this project since the Arduino IDE is designed for beginners.  I would have given up in frustration if I had to use the Arduino IDE to develop these project.

A quick summary of the changes I made:

  • Added support for 5 mouse buttons
  • Added an absolute mouse HID
  • Increased the power that the Teensy requests from the USB host (aka computer)
  • Removed support for the joystick (not necessary in my application)

I just went and updated Paul’s latest repo with my changes, which are reflected in the following git diff.  My recommended method of adding these features, if desired, is to use the application provided by Paul to get the base environment, then add the changes from there.

Continue reading

Converting Text Ebooks into Audio ogg files

Text to speechI’ve recently started a job that requires a 1 hour commute each way, and so I decided to make the most of it by listening to audio books.  I’ve finished about 3 audio books so far, but I realize that I will soon run out of interesting content to listen to (I’ve been listening to LibreVox free public domain audio books).

Exploring the world of Text To Speech (TTS) software led me to first examine espeak, which had too much of a robotic tone for my liking.  I then stumbled upon Pico TTS on my cheap android tablet, which sounded too good to be true.  Looking around, I found a linux project that uses it, PicoSpeaker. Pico is a TTS solution from the company SVOX Mobile Voices, which apparently specializes in text to speech solutions for devices.  I’m not sure how the product ended up in linux as the packages sox and libttspico0, but they are their, and they work reasonably well.  The frustrating problem I found, was that PicoSpeaker didn’t accept large files.  So frustrating was this problem, that I continued to look around at different fixes.

I then checked out Festival, installed better voices, and still found the quality lacking in comparison to Pico TTS.  I played with the gain, rate, pitch to make the different voices sound better to me, but it failed to make a difference (I tried out the MBROLA and CMU Arctic voices, samples here).    Even though I could convert a complete file with these, they didn’t sound as good to my subjective ears.

To cut a long story short, much of my Saturday was spent on getting a TTS solution which would help me convert Text books to Audio books.  To fix the file size limitation problem, I split up the file into 100 line parts with:

split -l 100 -d -a 4 Ebook_ Text_To_Convert.txt

This creates a set of text files with no extension, starting at Ebook_0000.  Next I created the following script, which I named


if [ $# -eq 0 ]
echo “Type the base name of the file to convert, followed by enter:”
read name

echo “Type name of author: ”
read author

echo “Type name of book: ”
read book

for f in $name*;
echo “Converting $f ..”
cat $f | ./picospeaker -o $f.ogg;

echo “Now adding tag information”

lltag –yes –clear -a “$author” -A “$book” -t “$f” $f.ogg

I run this script by making the script executable (chmod +x and provide it with the base name (Ebook_ in this case), the title of the Author (“Henry Thoreau” for example), and the title of the book.  Note that if any of those have spaces, you need to put the words in quotes.

The end result is a pretty decent sounding audio book, that I can actually play at 120% (with the -r 20 flag provided to picospeaker) with all of the words intelligible. Here is a 6 minute sample of the audio, uploaded on Picosong (Picosong seems to be like the imgur of audio links, pretty nice service).  This is a sample of it as I like to listen to it.

You may need an additional step to convert the audio into an mp3 format, and to do that, add the following before lltag:

ffmpeg -i $f.ogg -ab 128k $f.mp3

Note that this creates a larger file than the ogg, I’m not sure of the settings to make it better, but for now it will work.  Better to ship something working, than nothing at all.

New Project Added: FastDigitalWrite for Arduino 1.0

… “But hasn’t this been done before?”  YES!  And I didn’t do it. I didn’t do it this time either 😛

I was reading Bill Porter‘s article about how many cycles it takes to do a digitalWrite as fast as you can in Arduino.  He compared it to the speeds attained by writing directly to the port, and he found that a digitalWrite operation takes 56 clock cycles to perform, whereas a direct port write takes 2 clock cycles.  He referred to a library that rewrote digitalWrite in terms of a macro (something I was thinking of doing, but I’m glad I didn’t, cause John Rain? with the assistance of Paul Stoffregen and Bill Westfield worked out the details of doing it).

The problem with that library, is that the last update was in 2010, and after trying, it didn’t work with Arduino 1.0.  The original file was provided as a library for arduino, but it included a ‘bonus’ section that had the macroized digitalWrite, digitalRead, and pinMode.  I’ve updated just those files for Arduino 1.0, and I have it hosted here. I have a few readme’s in there, the .txt readme is one I created, which tells you where to put the files.  But I have arranged it so that after you extract it, you can copy the lib and hardware folders to your arduino installation, and copy and replace your existing files.  The trick to their modifications is only using the original digitalWrite routine if the pin number or level specified changes.  For me, most of my digitalWrite and reads are static, same pin number, everytime.

As always, this comes with no warranties.  When comparing the Blink sketch, the size went from 1026 bytes to 674.  For my controller sketch, it went from 16708 to 16642 bytes.  I hope everyone enjoys this, and feel free to ask me any questions.


XBee and BTM-182 configured via Arduino

I finally got my Ardunio to successfully configure both the XBee and this BTM-182 bluetooth serial module. Why would you want to do that? Well the XBee has six 10-bit resolution Analog to Digital Converter channels, and about 8 digital IO channels (all ADC channels double as DIO channels, so in total about 8 to play with). Another reason is if you want to only talk to one remote xbee module rather than them all, you could change it on the fly. For the bluetooth module, you can perform scanning of available BT things, and connect to them, all using the ‘Command’ mode.

This is another lesson for KISS I think, since when I first started to tackle this problem, I made these fancy functions to handle it. Well that didn’t work at first, but after some massaging, I got it working. Then I tried to get software serial working, but that didn’t work out. (I thought I configured it correctly, turns out I needed to declare inputs/outputs for the SW serial port)

Ultimately I decided to try the simplest while loop to handle the response, which worked out really well. I found out how to get the SW serial working by looking at this example which had SW serial running (the default examples in Arduino 1.0 IDE didn’t setup the input/output). I’ve attached the code below, it’s not pretty, but sharing is caring 😛

What you see in the picture are two NunChucks that I intend to get setup and running, and once they are running, I can send the joystick response anywhere 😛 Once I get some parts in for the controller, I’ll go ahead and build it up. Then something to interface with (plant waterer). Fun times!!!

Continue reading

Finding Parts is a Skill…

Let’s say you want to buy some 10 pin connectors to connect your boards together, it should be pretty easy to buy them, right? Sure! Just go to Sparkfun and spend $1.50 for a 40 pin female header and another $1.50 for a 40 pin male header. Wow, that’s expensive.

The trick to navigating Digikey or Mouser, is being able to select the right terms that get you to what you actually want, and sometimes that is trial and error. Let’s look at Mouser. Looking at the link itself, I had to go to Interconnects -> Rectangular Connectors -> Headers wire housings, then selecting male.  From there, I could then look for the actual specifications for the part I want (cheap, 2.54 mm pitch, 1 row).

Many times I get a little frustrated trying to navigate the menus, but it is usually always worth it, in $, to do so. In this case, I found the best prices at, $0.33 for each (since I’m buying 100, the price is $0.15). They had the best prices for the female connectors as well. But they lacked quite a few parts, so I will still have to order at Mouser, but I think I’ll save money by ordering from both places, rather than getting it all from Mouser.

Learning how to navigate vendors like Digikey, Mouser, Newark, and ebay can help you save lots of money versus buying parts at specialty places like Sparkfun or Pololu. In this case, I can buy 5 headers from DipMicro versus 1 from SparkFun. Wowza!

As a sidenote, I’m buying a non-latching shift register to see if I can reduce the pins needed to drive an LCD to two, using the Shift LCD library! I’m thinking of picking up a PS2 connector, as well as a NunChuck adapter, to make things nicer, even though they will probably cost more than an entire MCU + Wireless + Case combo…

Dual Serial to TTL/FTDI Board

This slideshow requires JavaScript.

Yesterday I solved my ATmega328 woes, turns out one of the MCU’s had a bad flash, since reflashing it made it work as expected. But with 2 wireless to serial boards, it would mean that I needed another serial to ttl board.  I decided to go ahead and solder my original one up, and add an LED to it.

Since the MAX3232 has 2 Serial to TTL transceivers, I decided to go ahead and set it up to use both.  Most of the time when I’m using serial, I’ll be at my desk, which is where my projects would be too.   I can forsee times in which I have 2 serial things connected to my computer at once, so I went ahead and made it.

I setup the output connectors so its FTDI compatible.  So I can plug in a RBBB or a JeeNode (unlikely that I’ll ever get one, they are expensive).  I think I’ll make the FTDI connector a standard connector that I’ll use on my projects.  The power pins for this do not supply power, so the guest MCU will have to supply power, which is great if you don’t want to send 5V to a 3.3V system, or 3.3V to a 5V system.  I even have a jumper setup so I can choose which powers the MAX3232, which controls the voltage levels of the communication.

Most of my guest MCU’s would already have a voltage regulator and battery source, so I don’t see this as a problem, but I could always add a 3.3V or 5V voltage regulator if needed.

I consider this as a mini project, and by thinking it up, drawing it out, and finishing it, it gives me more motivation to continue, since I just made something!

USBasp… was a Failure!

So I built it, I tested it.  The usb worked fine, but it would never detect the to-be-flashed MCU.  I did a little thinking, and I think I will shelve this idea for now.  I couldn’t get it to work, the circuit is as described, I even tried 2 different circuits.

So I moved on… to upgrading my Bus Pirate with 40x faster firmware.  It makes the ISP much quicker to use.  I will eventually play around with Arduino ISP, but not yet.  Thats all I pretty much accomplished…  Oh I modified the programmers.txt and boards.txt files for arduino to add a 8MHZ board option for my ATMEGA328…

That reminds me, I discovered that I purchased 25 ATMEGA328’s, not ATMEGA328P’s.  It turns out that P means pico power, so my MCU’s will not be as energy efficient as the ATMEGA328P’s.  Be careful when buying components!   The price point makes it worth it to me though, since I’m aiming to make the cheapest diy arduino kits.


USBasp debugging

So I’ve been working on getting this USBasp working, and so far it has been pretty good.  I got the firmware flashed to the ATMEGA48p, and when I plug it into the computer, it recognizes it via USB!  But I haven’t been able to get it to flash a MCU yet.

Good news is that when I was first playing with it, I noticed that my mouse and keyboard (connected to the same USB hub) started to act funny.  Eh, I can live with that.  Same thing happened in Windows (I flashed it in Linux).  Eventually, the smell of components heating up struck my nose, and I quickly unplugged it.  It turns out, I connected Pin 7 and 8 of the MCU-to-be-flashed, to power.  So that MCU got really hot.  I was amazed that it still is detected using my Bus Pirate, I was sure that it was toast!

I considered playing with the PS2 controller, but this had my attention, so I kind of had to go with the flow.

I have several ideas why it may not be working:
-the ATMEGA48 that I have is the 10PU version, only rated up to 10MHz.  But since it is detected via USB, I’m not sure this is a problem.
– Perhaps I need to disconnect the to-be-flashed chip when I plug in the USBasp?

I’ll try to update tonight about my progress. 🙂