Can be used as a replacement of the original LEGO IR serial tower with programs and platforms such as
- WebPBrick: web-based NQC IDE (see also: github.com/maehw/WebPBrick/)
- Bricx Command Center (BricxCC): 32-bit Windows IDE
firmdl3
command line download tool- probably other software
to load user programs and firmware on the yellow LEGO Mindstorms RCX programmable brick.
Pin Assignment Table for the ATtiny13A:
IC Pin | Pin | Purpose | Direction | Side of IC | ISP Usage |
---|---|---|---|---|---|
1 | PB5 | Reset | Unused | Left | Reset |
2 | PB3 | IR_LED_TX_PIN | Output | Left | |
3 | PB4 | PHOTO_RX_PIN | Input | Left | |
4 | GND | Ground | - | Left | GND |
5 | PB0 | UART_RX_PIN | Output | Right | MOSI |
6 | PB1 | UART_TX_PIN | Input | Right | MISO |
7 | PB2 | IR_ACTIVITY_LED_PIN | Output | Right | SCK |
8 | VCC | Supply Voltage (VCC) | - | Right | VCC |
The column "ISP Usage" shows what pins need to be connected for programming ("flashing") by a 6-pin AVR In-System Programmer (ISP).
- ATtiny13A as microcontroller (calibrated internal 9.6 MHz oscillator as clock source; other uCs such as the ATtiny85 may work as they have more SRAM and more flash memory, but timing values will need to be adjusted)
- Vishay Semiconductors TSOP4338 38 kHz infrared receiver (others 38 kHz infrared receivers may work)
- Vishay Semiconductors TSAL6200 940 nm infrared TX LED (others 940 nm infrared TX LEDs may work)
For breadboard see image above. The Fritzing breadboard diagram looks as follows (please also pay attention to the hints inside the image):
An alternative would be a solder breadboard to make something semi-permanent (the green activity LED is hidden between the jumper wires of the USB/serial converter cable):
Find the productive firmware in folder ./firmware
.
- GNU C cross compiler for AVR 8-bit
gcc-avr
(other build toolchains may work as well) avrdude
: program for downloading and uploading the on-chip memories of AVR microcontrollers (or another similar tool)
To build, run:
avr-gcc -g -Wall -Os -mmcu=attiny13a -o main.elf main.c
(Append the verbosity flag -v
to see what's going on behind the scenes.)
Want to check if it will it fit into the internal flash?
avr-size main.elf
text data bss dec hex filename
776 0 7 783 30f main.elf
Make sure to burn the microcontrollers fuses so that
- the calibrated internal 9.6 MHz oscillator is selected
- clock pre-scaler set to 1 (device is shipped with CKDIV8 programmed).
Reading fuses with avrdude (and in this case an ehajo-isp
in-system programmer):
avrdude -c ehajo-isp -p t13a -U hfuse:r:-:h -U lfuse:r:-:h
The default values for the two fuse bytes of the ATtiny13A are 0xff
(high), 0x6a
(low) and match the oscilator and clock pre-scaler conditions.
(Hint: If the avrdude
version being used gives "avrdude: AVR Part "t13a" not found.", try using t13
instead of t13a
.)
Finally, flash the firmware:
avrdude -c ehajo-isp -p t13a -U flash:w:main.elf:e
Please note that under ./test/firmware
, there's some more code to test the assembled hardware. The commands from above can be reused, only the filename needs to be changed.
blink.c
will blink the the activity indication LED and hence allow to check if the LED is working and the compilation and flashing also wokrs.
serial_echo.c
will echo the serially received UART characters. Please note that this example does not make use of any uC UART peripheral but only relies upon GPIO pin edge detection on the "UART" receive pin. This can be used with any terminal emulator that works with serial devices or with the Python script /test/scripts/serial_coms.py
to send and receive binary data:
$ python serial_coms.py -h
usage: serial_coms.py [-h] serial_device data_to_send
Send binary data over serial and receive response.
positional arguments:
serial_device Name of the serial device (e.g., '/dev/ttyUSB0')
data_to_send Binary data to send in HEX format (e.g., '55FF00609F609F')
options:
-h, --help show this help message and exit
Example:
$ python serial_coms.py /dev/ttyUSB0 11223344
[TX] 11 22 33 44
[RX] 11 22 33 44
The same four bytes are received which have been transmitted before - just as you'd expect from an echo application!
LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this project.