Week 10 Assignments
Table of Contents
Week 10 - Input devices
This week we must create a board that contains an input to device and measure it from the computer. As I want to create an interactive playground, I'll opt for light sensors to detect when players cover joints with their hands.
Milling the board
I used hello.light board for this week, that includes a phototransitor to detect light. I milled the board using Modela MDX and soldered it. These are the required components:
Here it is the resulting board:
Uploading code
To upload the code, I used the avr programmer connected to the ICSP header to upload the file:
Afrodita:FabAcademy satch$ cat hello.light.45.make
PROJECT=hello.light.45
SOURCES=$(PROJECT).c
MMCU=attiny45
F_CPU = 8000000
CFLAGS=-mmcu=$(MMCU) -Wall -Os -DF_CPU=$(F_CPU)
$(PROJECT).hex: $(PROJECT).out
avr-objcopy -O ihex $(PROJECT).out $(PROJECT).c.hex;\
avr-size --mcu=$(MMCU) --format=avr $(PROJECT).out
$(PROJECT).out: $(SOURCES)
avr-gcc $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES)
program-bsd: $(PROJECT).hex
avrdude -p t45 -c bsd -U flash:w:$(PROJECT).c.hex
program-dasa: $(PROJECT).hex
avrdude -p t45 -P /dev/ttyUSB0 -c dasa -U flash:w:$(PROJECT).c.hex
program-avrisp2: $(PROJECT).hex
avrdude -p t45 -P usb -c avrisp2 -U flash:w:$(PROJECT).c.hex
program-usbtiny: $(PROJECT).hex
avrdude -p t45 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex
program-dragon: $(PROJECT).hex
avrdude -p t45 -P usb -c dragon_isp -U flash:w:$(PROJECT).c.hex
Afrodita:FabAcademy satch$ sudo make -f hello.light.45.make program-avrisp2
Password:
avr-gcc -mmcu=attiny45 -Wall -Os -DF_CPU=8000000 -I./ -o hello.light.45.out hello.light.45.c
avr-objcopy -O ihex hello.light.45.out hello.light.45.c.hex;\
avr-size --mcu=attiny45 --format=avr hello.light.45.out
AVR Memory Usage
----------------
Device: attiny45
Program: 530 bytes (12.9% Full)
(.text + .data + .bootloader)
Data: 1 bytes (0.4% Full)
(.data + .bss + .noinit)
avrdude -p t45 -P usb -c avrisp2 -U flash:w:hello.light.45.c.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9206
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "hello.light.45.c.hex"
avrdude: input file hello.light.45.c.hex auto detected as Intel Hex
avrdude: writing flash (530 bytes):
Writing | ################################################## | 100% 0.20s
avrdude: 530 bytes of flash written
avrdude: verifying flash memory against hello.light.45.c.hex:
avrdude: load data flash data from input file hello.light.45.c.hex:
avrdude: input file hello.light.45.c.hex auto detected as Intel Hex
avrdude: input file hello.light.45.c.hex contains 530 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.17s
avrdude: verifying ...
avrdude: 530 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done. Thank you.
Reading the values from the computer
To read values from the console I used the hello.light.45.py file. I installed PySerial previously, but somehow I got these errores related to permissions and some missing files.
Afrodita:FabAcademy satch$ ./hello.light.45.py /dev/tty.usbserial-FTF3M8JF -bash: ./hello.light.45.py: Permission denied Afrodita:FabAcademy satch$ sudo ./hello.light.45.py /dev/tty.usbserial-FTF3M8JF Password: sudo: ./hello.light.45.py: command not found Afrodita:FabAcademy satch$ chmod +x hello.light.45.py Afrodita:FabAcademy satch$ sudo ./hello.light.45.py /dev/tty.usbserial-FTF3M8JF from: can't read /var/mail/Tkinter dyld: Library not loaded: /usr/local/lib/libltdl.7.dylib Referenced from: /usr/local/bin/import Reason: image not found ./hello.light.45.py: line 16: 62833 Trace/BPT trap: 5 import serial ./hello.light.45.py: line 18: WINDOW: command not found ./hello.light.45.py: line 19: eps: command not found ./hello.light.45.py: line 20: filter: command not found ./hello.light.45.py: line 22: syntax error near unexpected token `(' ./hello.light.45.py: line 22: `def idle(parent,canvas):' Afrodita:FabAcademy satch$
I did some basic troubleshooting but in the end, I just discovered I also missed some TKinter files. Following this python tutorial I determined I needed to install and configure ActiveTcl 8.5.14 for my 2.7.x 64 bits python release.
Afterwards I was able to run the code without problems. I was surpised as the counter ran in the opposite direction I expected, running high under no light and viceversa. I also determined that de dynamic range of this particular sensor is not very suited to indoors, as it always oscilated between 930 and 1024.