Older blog entries for shimniok (starting at number 42)

Sparkfun AVC 2014 Announced

Sparkfun has announced the date and venue for the 2014 Autonomous Vehicle Competition. June 21st at the Boulder Reservoir. Details here.

Syndicated 2013-11-18 16:49:00 (Updated 2013-11-18 16:49:08) from Michael Shimniok

ATtiny Software Serial

ATtiny software serial transmit and receive, based the Arduino SoftwareSerial library, and around 1K compiled. That's what I've been working on. Why?

Spy photo :) of ultra compact eeZeeISP AVR programmer
I'm designing a low cost, really small AVR Programmer, that's why. It's based on an ATtiny84A and requires SPI which claims the USI peripheral, leaving no hardware serial.

Here are the details on TinySoftSerial.


The current Arduino
SoftwareSerial library is based on the NewSoftSerial library by Mikal Hart. A few years ago, NewSoftSerial was a dramatic improvement over then-incumbent SoftwareSerial, which is why the new code is part of the Arduino 1.0.x distribution.

Multiple serial listeners are supported at baud rates from 300 to 115200 though errors above 38400 at 16MHz may be too high and lower rates too slow. Overall, it's a really neat library for typical communications of 9600 - 38400.

So you may see why, when I needed serial receive (the hard part), I didn't really feel like reinventing the wheel. I need the library for other projects, too. But I needed something small and with only one software serial instance.

What I Did

  • Converted to C
  • Removed multiple instance capability
  • Converted to native PORTx/PINx/DDRx register references
  • Hardcoded to use PA0 for RX and PA1 for TX
  • Shaved a few bytes here and there,
    • e.g., using a mask instead of modulo for circular buffer**
  • Adapted interrupt register references to ATTiny84A: GIMSK, PCMSK0
  • Hardcoded 16MHz timings (for now; I may restore the other frequencies later)
  • Fixed "Error: register r24, r26, r28 or r30 required" - details
  • A few other things I can't remember
The result is pretty small. The following is for the library with a simple main() that echoes characters you type:

  avr-size --format=berkeley -t TinySoftSerial.elf
   text    data     bss     dec     hex filename
   1008       2     204    1214     4be TinySoftSerial.elf
   1008       2     204    1214     4be (TOTALS)
Finished building: sizedummy

** If you're curious about using a mask instead of modulo. Let's say you have a buffer of 64 bytes (or any number 2n), aka 0x40 or 26. Indexes range from 0x00 to 0x3f or 000000 to 111111. After you increment your index, simply AND it with 0x3f (2n-1). Suppose the index is 0x3f, the maximum and you increment it to 0x40. Now AND with 0x3f and you get 0x00  (%01000000 & 111111) . This is faster and uses fewer assembly instructions to implement than modulo or an if statement. Here's what it looks like in C:

#define MAXBUF 64
#define BUFMASK (MAXBUF-1)
char buf[MAXBUF];
i = (i+1) & BUFMASK;

The Code

I bet you just want the code. Ok, here it is.

Source Code

Porting to ATtiny85, Etc.

It shouldn't be too hard to port this to ATtiny85. You could port to ATtiny2313 although it has hardware serial separate from the USI. The library is too big for ATtiny13 to do anything useful. I don't use any other ATtinys but basically anything that has 2K flash or higher should be a go.

Saleae Logic Analyzer: STK500 V2 protocol

Syndicated 2013-11-14 17:00:00 (Updated 2013-11-14 19:42:47) from Michael Shimniok

9 Nov 2013 (updated 9 Nov 2013 at 20:12 UTC) »

Robot Art

My best friend is an artist. His latest blog post features some of the robot head art he's been working on. His prices are reasonable so if you want one, let me know and I'll put you in touch.

Syndicated 2013-11-09 16:46:00 (Updated 2013-11-09 17:42:12) from Michael Shimniok

JavaOne: Raspberry Pi Embedded Challenge

After a couple late night hours at JavaOne Java Embedded Challenge, Bruno and I had written a field sobriety tester on a Raspberry Pi using JavaFX and Java Embedded Suite. It's an example of how easy it is to build embedded solutions when all the hard work is already done for you :) Here's what we put together...

A few weeks ago I was fortunate enough to attend the JavaOne conference. I was there for purposes other than blog fodder but by happy coincidence, I stumbled across the Raspberry Pi Embedded Challenge in one of the first presentations of the event.

In the evenings, on personal time, a handful of us committed to hacking up some code on Raspberry Pi using Java Embedded Suite, Arduino, a big board of sensors, and a slick RPi-Arduino interface API (
things-api) written by Vinicius Senger.

Bruno P. and I teamed to create a Field Sobriety Tester that incorporates an alcohol sensor and a "drunk swaying" sensor, that is, a Ping))) distance sensor. The distance sensor is graphed and value displayed, the alcohol monitor value is also displayed.

That's me talking about the JavaFX display
Our source code is posted on github.


The basic architecture begins with a JavaFX client running on our laptops. The client could just as easily run on the Raspberry Pi. In fact, JavaFX can directly write to the RPi's frame buffer hardware, bypassing X.

The Raspberry Pi is running Oracle Java Embedded Suite, basically like a lightweight, embedded J2EE.

The Embedded Suite is running things-api code, exposing Arduino sensors as REST web services. The RPi's things-api web services talk to Arduino's things-api code over serial. The Arduino in turn interfaces with sensors in the standard fashion.

Things-API Arduino

On the Arduino side, defining sensors is beautifully simple. Declar a Device object, then add things to it, defining the pin type and pin number, e.g., Analog pin 2. Then just loop calling loop functions.