Files: [embedded](https://gitlab.cba.mit.edu/erik/attiny44a_blink)(see button_serial.c) [test_app](https://gitlab.cba.mit.edu/erik/serial_cpp)[shelf_app](https://gitlab.cba.mit.edu/erik/htmaa_shelves) (see shelf_button.cpp)
This week we're diving deeper into communication between micrcontrollers and computers.
## Recitation
Since Amira doesn't have her magnetic field detector from [HTM(a)A 2016](http://fab.cba.mit.edu/classes/863.16/section.Harvard/people/Abdel-Rahman/index.html)(see week 12), I loaned her my hello world [button board](../06_electronics_design). But it needed a minor code update to be useful. I used Neil's [serial bit banging](http://academy.cba.mit.edu/classes/embedded_programming/index.html#echo) code once again, and made my board output a constant stream of characters on the FTDI header. When the button is not pressed it outputs `'0'`, and when it is it outputs `'1'`. I wasn't able to make it, but I hear the live demo worked.
## Exploration
I want to approach serial communication from a pretty low level, so I'm going to use a C or C++ library. Using OS-specific system calls (as is ultimately pretty much necessary) is a bit too deep, though, since I'd like to be able to write cross-platform code. From some quick googling it looks like the two most popular cross-platform C libraries are [libserial](http://libserial.sourceforge.net/) and [libserialport](https://sigrok.org/wiki/Libserialport). They seem mostly equivalent in features, but libserialport works on Windows in addition to POSIX systems, and Homebrew has a tap for it. Decision made.
The homebrew install worked fine, and I set up a quick test program in C++ based on an [example](https://gist.github.com/Nixes/78e401234e66aa131547d7b78135271c) I found on GitHub. (For those that are curious, I made an imported library target for libserialport in cmake. So that's where I record include directories and linking steps.)
In the video above I'm just reloading one of four generated SVG files (since the shelves at their biggest require four panels of material). But it's also generating ShopBot code for each panel as well. So after pressing the button you're fully ready to cut. All of this happens in less than the blink of an eye -- the delay is just from Chrome being slow at reloading.
What I'm not doing is generating a 3d model of the shelves... It would be fun to do that in three.js, and communicate with my shelf app over a websocket. Unfortunately I don't have time this week.