Week 16: Interface and application programming

For this week I took the board from week 11 inputDev to use the magnetometer to interface with an application. First, I needed to test the serial connection as I didn't test it on its week, just put the ftdi connector. The first problem is that I can't find my original ft232 board, and I have another couple of them but they won't work on Windows. You can read more about that here

Good thing is that I have an old Arduino Duemilanove, with an ATmega328P, which is a DIP chip that can be removed from the socket, thus disconnecting the only serial device attached to the FTDI chip and now I can use pins 0 and 1 as RX and TX. So as I want to make the application in Python, I'm going to check if Neil's helloMag project works with my board and then take care of the interface programming only.


ftdiduino

It works nicely, so now I'm going to make a simple Arduino sketch, that reads the sensors and sends them values over serial. For that, I'm using the SoftwareSerial library. Now with that couple of values being sent, it's time to write something that reads and makes something with them. The Serial communication protocol , meaning that only one bit of data is transmitted trough the line. It is a 2 wire communication, having a TX and RX connections, the TX output of one device should be connected to the RX input of the device we are talking to. Sometimes, boards are marked not as what they are (TX or RX) but with what should be connected, this happens also with MISO and MOSI when using SPI. The Serial protocol can be implemented on a chip as a hardware feature having a buffer that allows the microprocessor to do other tasks while receiving serial data, this is called UART. UART is usually located on fixed pins, meaning that if you want to use it, you should keep those pins just for serial communication. But unfortunately the ATtiny family doesn't include this feature, so I'm using a SoftwareSerial library. This means that instead of the UART, the microcontroller is going to manage the communication by switching the output and reading the input simulating the UART behaviour. Using the UART is generally better as it won't lock execution, but in some cases when you need extra serial devices (remember Serial is not a bus like I2C or SPI, it's a point to point communication) you'll need to use a software serial. As for this week I'm using the Arduino bootloader and IDE, I'm using this library included in the core libraries of the Arduino IDE.



So I've used Firmata and Processing in a couple of projects to communicate sensors and prototype a small app that uses them. So for this week I'll make something different. I've stated several times these previous weeks about how I don't know Python but is something I always want to learn. So continuing with the work I've made on the MTM project "McNulty" when I've used wx to make together with Borja the GUI for the machine application.

Here's the python program called inputInterface.py It just reads values sent over serial and draws something using those values as variables, so I can modify shapes with a magnet and light.



I decided then to try some audio and make a oscillator controlled by those sensor on what would be a Theremin like instrument, but I'm still testing libraries to do so.


inputInterface

Video

In the video, there are two point clouds, that are generated as a mix of a random number and the values of light and magnetic field read by the board. The cloud on the left is altered with light, and the cloud on the right changes with the hall effect sensor value. Both the position an density of the cloud are controlled with those parameters. With low compression in order to get the video within a few MB, the dots are not very clear though.

Machines and software used

SO: Ubuntu 14.04
python

Files

inputInterface.py
magSerial.ino

  • Learning outcomes:
  • Yes Interpret and implement programming protocols
  • Have you:
  • Yes Described your process using words/images/screenshots.
  • Yes, Serial and SoftwareSerial Explained the protocols you used
  • Yep! Had a fun time
  • Yes, had to use an Arduino as ftdi Outlined problems and how you fixed them
  • Yes Included original code