From bb754d409df4ad34617e7f76df8cf94e2ecf0a2a Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sat, 25 Jan 2020 23:37:41 -0800 Subject: [PATCH] . --- listen-python | 16 ++++++++++++++++ listen.sh | 4 ++-- main.c | 30 +++++++++++++++++++----------- 3 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 listen-python diff --git a/listen-python b/listen-python new file mode 100644 index 0000000..f02d8ab --- /dev/null +++ b/listen-python @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import serial, string + +output = " " +ser = serial.Serial('/dev/ttyUSB0', 9600, 8, 'N', 1, timeout=1) +while True: + while output != "": + output = ser.read(1) + print len(output) + try: + print int(output) + except ValueError: + print ":".join("{:02x}".format(ord(c)) for c in output) + print output + output = " " diff --git a/listen.sh b/listen.sh index 869d703..ef5ccd5 100755 --- a/listen.sh +++ b/listen.sh @@ -1,6 +1,6 @@ #stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts -stty -F /dev/ttyUSB0 9600 -parenb -parodd cs8 -hupcl \ +sudo stty -F /dev/ttyUSB0 9600 -parenb -parodd cs8 -hupcl \ -cstopb cread clocal -crtscts -iuclc -ixany -imaxbel \ -iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill \ -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten \ @@ -8,4 +8,4 @@ stty -F /dev/ttyUSB0 9600 -parenb -parodd cs8 -hupcl \ -echoctl -echoke -tail -f /dev/ttyUSB0 +sudo tail -f /dev/ttyUSB0 diff --git a/main.c b/main.c index 7ac8206..1a9c2da 100644 --- a/main.c +++ b/main.c @@ -3,8 +3,11 @@ #include #include #include + #define LED PORTD2 -#define WIRE PORTD3 +#define PULL PORTD3 +#define ENABLE PORTD5 +#define DIRECTION PORTD6 void uart_init() { @@ -35,6 +38,7 @@ void uart_putstr(char *data) { } + int main(void) { uart_init(); @@ -42,20 +46,24 @@ int main(void) { DDRC &= ~(1<<0); // Input PORTC |= (1<<0); // Enable Internal Pull Up (Setting it to HIGH) - DDRD |= (1 << WIRE); - +// DDRD |= (1 << ENABLE); + DDRD = DDRD | 0xFC; + + PORTD |= _BV(ENABLE); + PORTD |= _BV(DIRECTION); + for(;;){ - uart_putstr("hello\n"); - _delay_ms(900); - PORTD |= (1 << WIRE); - _delay_ms(900); - PORTD &= (0 << WIRE); +// uart_putstr("hello\n"); + _delay_ms(400); + PORTD |= _BV(PULL); + _delay_ms(400); + PORTD &= ~_BV(PULL); - uint8_t port_value = 0; - port_value = PINC & (1 << 0); + uint8_t port_value = 2; +// port_value = PINC & (1 << 0); uart_putchar((char)port_value); - uart_putstr("\n"); +// uart_putchar((char)'\n'); } }