.
This commit is contained in:
16
listen-python
Normal file
16
listen-python
Normal file
@@ -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 = " "
|
||||||
@@ -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 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 \
|
-cstopb cread clocal -crtscts -iuclc -ixany -imaxbel \
|
||||||
-iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill \
|
-iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill \
|
||||||
-ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten \
|
-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
|
-echoctl -echoke
|
||||||
|
|
||||||
|
|
||||||
tail -f /dev/ttyUSB0
|
sudo tail -f /dev/ttyUSB0
|
||||||
|
|||||||
30
main.c
30
main.c
@@ -3,8 +3,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <util/setbaud.h>
|
#include <util/setbaud.h>
|
||||||
|
|
||||||
#define LED PORTD2
|
#define LED PORTD2
|
||||||
#define WIRE PORTD3
|
#define PULL PORTD3
|
||||||
|
#define ENABLE PORTD5
|
||||||
|
#define DIRECTION PORTD6
|
||||||
|
|
||||||
|
|
||||||
void uart_init() {
|
void uart_init() {
|
||||||
@@ -35,6 +38,7 @@ void uart_putstr(char *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
uart_init();
|
uart_init();
|
||||||
@@ -42,20 +46,24 @@ int main(void) {
|
|||||||
DDRC &= ~(1<<0); // Input
|
DDRC &= ~(1<<0); // Input
|
||||||
PORTC |= (1<<0); // Enable Internal Pull Up (Setting it to HIGH)
|
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(;;){
|
for(;;){
|
||||||
|
|
||||||
uart_putstr("hello\n");
|
// uart_putstr("hello\n");
|
||||||
_delay_ms(900);
|
_delay_ms(400);
|
||||||
PORTD |= (1 << WIRE);
|
PORTD |= _BV(PULL);
|
||||||
_delay_ms(900);
|
_delay_ms(400);
|
||||||
PORTD &= (0 << WIRE);
|
PORTD &= ~_BV(PULL);
|
||||||
|
|
||||||
uint8_t port_value = 0;
|
uint8_t port_value = 2;
|
||||||
port_value = PINC & (1 << 0);
|
// port_value = PINC & (1 << 0);
|
||||||
uart_putchar((char)port_value);
|
uart_putchar((char)port_value);
|
||||||
uart_putstr("\n");
|
// uart_putchar((char)'\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user