Ultrasonic Distance Sensor | Week10 Input Devices |
R1: | Resistance | 10k [ohm](1002) | x 1 | |
C1: | Capacitor | 1u [F] | x 1 | |
IC1: | Attiny 44 | x 1 | ||
JP1 ISP: | Pin header | 2x3 | x 1 | |
FTDI: | Pin header | 1X4 | x 1 | |
HC-SR04: | Pin holder | 1X4 | x 1 | |
LED: | WS2812B | x 3 | ||
R2: | Resistance | 100 [ohm](101) | x 3 | |
C2: | Capacitor | 0.1u [F] | x 3 |
PA1 is connected to FTDI's RT(= ATtiny's TX) |
PB0 is connected to Sensor's Trigger |
PB1 is connected to Sensor's Echo |
hello.HC-SR04.c | myhello.HC-SR04.c | |
#define serial_port PORTB #define serial_direction DDRB #define serial_pin_out (1 << PB2) #define trigger_port PORTB #define trigger_direction DDRB #define trigger_pin (1 << PB3) #define echo_pins PINB #define echo_direction DDRB #define echo_pin (1 << PB4) |
#define serial_port PORTA #define serial_direction DDRA #define serial_pin_out (1 << PA1) #define trigger_port PORTB #define trigger_direction DDRB #define trigger_pin (1 << PB0) #define echo_pins PINB #define echo_direction DDRB #define echo_pin (1 << PB1) |
$ make -f myhello.HC-SR04.make avr-gcc -mmcu=attiny44 -Wall -Os -DF_CPU=8000000 -I./ -o myhello.HC-SR04.out myhello.HC-SR04.c myhello.HC-SR04.c: In function 'main': myhello.HC-SR04.c:141:7: error: 'TIFR' undeclared (first use in this function) TIFR |= (1 << TOV0); ^ myhello.HC-SR04.c:141:7: note: each undeclared identifier is reported only once for each function it appears in make: *** [myhello.HC-SR04.out] Error 1
$ make -f myhello.HC-SR04.make $ sudo make -f myhello.HC-SR04.make program-usbtiny-fuses $ sudo make -f myhello.HC-SR04.make program-usbtiny $ ls /dev | grep usb cu.usbserial-AI02RJUC tty.usbserial-AI02RJUC $ python hello.HC-SR04.py /dev/tty.usbserial-AI02RJUC