Interface and Application Programming

Please Speak Softly App

The app Please Speak Softly is written in C and Objective-C, the programming language native to Mac OS X.

It communicates with the embedded device over the serial protocol. To do that natively it uses the ORSSerialPort library, which is an Objective-C wrapper around Apple’s IOKitLib based on standard C POSIX functions like open(), select(), or close() (example).

A hello world would be as simple as:
#import <Foundation/Foundation.h>
#import "ORSSerialPort.h"
#import "ORSSerialPortManager.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        ORSSerialPort *serialPort = [ORSSerialPort serialPortWithPath:@"/dev/tty.usbserial-FTH7PIOR"];
        serialPort.baudRate = @115200;
        [serialPort open];
        [serialPort sendData:[@"X" dataUsingEncoding:NSASCIIStringEncoding]];
        [serialPort close];
    }
    return 0;
}

Download source code PleaseSpeakSoftly.zip

On the embedded side we implementation serial communication in software (bit banging), which is a cheap way that doesn’t require dedicated hardware. It can even be interrupt-driven and is the only way to do serial communication with the ATTiny45 and ATTiny44 chips. The ATMega328p can do USART.

A video posted by Raphael Schaad (@raphaelschaad) on

Schaaduino

To have a quicker turnaround when prototyping electronics, I started to develop my own reusable embedded boards with labeled breakout pins, similar to Arduino. Schaaduino is a family of Arduino-compatible boards that can be self-made and modified for the fraction of the cost.

There are three sizes that mainly differ in the available I/O pins: the ATTiny45-based Schaaduino MOUSE (seen in the picture above), the mid-size ATTiny44a-based Schaaduino CAT, and the big ATMega328p-based Schaaduino ELEPHANT.

Recitation Embedded Web Programming

We looked at three examples of how to use the web to interface with embedded devices:

  1. Web ⟷ device (over serial): JavaScript on web page ⇆ WebSocket ⇆ node.js server ⇆ npm serial module ⇆ FTDI Driver ⇆ AVR chip
  2. Web ⟷ device (directly): configure a ESP8266 WiFi chip (Tomer Weller knows this chip well) over serial to have a static IP (video) and talk via UDP (e.g. sensor readings) or TCP (e.g. webcam stream) directly to and from host computer
  3. Device as webclient/server: AVR chip → forms HTTP request → intraboard serial → ESP8266 sends out → web server request handling → … → HTTP response; or web browser → forms HTTP request → ESP8266 receives → intraboard serial → AVR onchip request handling → … → HTTP response (in practice websites are better served from e.g. a Raspberry Pi)