Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
workshop:arduino [2009-06-23 23:45] scolytus |
workshop:arduino [2009-06-24 00:53] equinox |
||
---|---|---|---|
Line 13: | Line 13: | ||
* [[http://arduino.cc/en/Guide/HomePage | Getting Started]] | * [[http://arduino.cc/en/Guide/HomePage | Getting Started]] | ||
* [[http://arduino.cc/en/Reference/HomePage| Arduino Language Reference]] | * [[http://arduino.cc/en/Reference/HomePage| Arduino Language Reference]] | ||
- | * [[http://www.atmel.com/dyn/resources/prod_documents/doc8025.pdf| Atmega328 Datasheet]] | + | * [[http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf| Atmega328 Datasheet]] |
* [[http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf| Arduino Duemilanove Schematics]] | * [[http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf| Arduino Duemilanove Schematics]] | ||
Line 47: | Line 47: | ||
Ein kleines Programm, um einen Arduino zu reseten. Funktionsweise: Auf den Duemilanove und anderen Boards ist die DTR-Leitung über eine Kondenstaor mit dem Reset-Pin verbunden. Wird die Leitung für 100ms auf low gezogen, enstehen ein negativer und eine positiver Spannungspuls, die ausreichen, das Reset durchzführen. Das passiert beim Anstecken, oder aber wenn folgendes Programm ausgeführt wird: | Ein kleines Programm, um einen Arduino zu reseten. Funktionsweise: Auf den Duemilanove und anderen Boards ist die DTR-Leitung über eine Kondenstaor mit dem Reset-Pin verbunden. Wird die Leitung für 100ms auf low gezogen, enstehen ein negativer und eine positiver Spannungspuls, die ausreichen, das Reset durchzführen. Das passiert beim Anstecken, oder aber wenn folgendes Programm ausgeführt wird: | ||
<code> | <code> | ||
+ | #include <stdlib.h> | ||
#include <termios.h> | #include <termios.h> | ||
#include <fcntl.h> | #include <fcntl.h> | ||
Line 52: | Line 53: | ||
#include <time.h> | #include <time.h> | ||
#include <stdio.h> | #include <stdio.h> | ||
+ | #include <sys/select.h> | ||
#define STATE_OFF 0 | #define STATE_OFF 0 | ||
Line 65: | Line 67: | ||
int | int | ||
- | main(void) | + | main(int argc, char* argv[]) |
{ | { | ||
- | const char device[] = "/dev/ttyUSB0"; | + | char* device = argc < 2 ? "/dev/ttyUSB0" : argv[1]; |
- | int fd; | + | int fd = open(device, O_RDWR); |
- | const struct timespec sleeptime = {0, 100000000}; // 100ms | + | |
- | + | ||
- | fd = open(device, O_RDWR); | + | |
if (fd == 0) { | if (fd == 0) { | ||
- | printf("Could not open %s\n", device); | + | fprintf(stderr, "Could not open %s\n", device); |
- | return 1; | + | return EXIT_FAILURE; |
} | } | ||
| | ||
- | printf ("Resetting %s\n", device); | ||
setDTRState(fd, STATE_ON); | setDTRState(fd, STATE_ON); | ||
- | nanosleep(&sleeptime, NULL); | + | struct timeval sleeptime = {0, 100000}; // 100ms |
+ | select(0, NULL, NULL, NULL, &sleeptime); | ||
setDTRState(fd, STATE_OFF); | setDTRState(fd, STATE_OFF); | ||
- | nanosleep(&sleeptime, NULL); | + | sleeptime.tv_sec = 0; |
+ | sleeptime.tv_usec = 100000; | ||
+ | select(0, NULL, NULL, NULL, &sleeptime); | ||
setDTRState(fd, STATE_ON); | setDTRState(fd, STATE_ON); | ||
close(fd); | close(fd); | ||
+ | |||
+ | return EXIT_SUCCESS; | ||
} | } | ||
</code> | </code> |
realraum Graz, Brockmanngasse 15, 8010 Graz, realraum - Verein für Technik in Kultur und Gesellschaft