.. vim: noexpandtab fileencoding=utf-8 nomodified wrap textwidth=270 foldmethod=marker foldmarker={{{,}}} foldcolumn=4 ruler showcmd lcs=tab\:|- list tabstop=8 noexpandtab nosmarttab softtabstop=0 shiftwidth=0 :date: 2023.08.24 03:20:17 :tags: HowTo :authors: Gilhad :summary: Arduino :title: Arduino :nice_title: |logo| %title% |logo| %HEADER% Arduino Serial až 2Mb/s (ale 115.200 je lepší) -------------------------------------------------------------------------------- * ale musely by se přepsat knihovny, aby stíhaly bufferovat ``__ * At 2 Mb/s, each byte transmission takes **80 CPU** cycles * takže pro **6309** by to bylo asi **10 cyklů** - nestíhá interrupty, nejspíš prostě nestíhá nic a budu rád za 115.200 na několika kanálech (aka 2 seriáky+vnitřní sběrnice k Polux3+ nebo tak něco) divmod10() : a fast replacement for /10 and %10 (unsigned) -------------------------------------------------------------------------------- ``__ no delay() blink -------------------------------------------------------------------------------- .. code:: unsigned long previous_millis, interval = 1000UL; if ( (current_millis - previous_millis) >= interval) { previous_millis = current_millis; // its the time }; Arduino Micro Serial -------------------------------------------------------------------------------- * Pro výstup na **Serial** používat `if (Serial.availableForWrite()) {Serial.print(F("whatever");};` * Pro monitorování pomocí `screen` nezapomenout shodit `RTS` a `DTR` třeba pomocí `close_Serial` (``__) .. code:: #include #include #include #include #include int main(int argc, char *argv[]) { // Check if the correct number of command-line arguments is provided if (argc != 2 ) { fprintf(stderr, "Usage: %s \n", argv[0]); fprintf(stderr, " %s /dev/ttyACM0 - close USB Serial for Arduino on the port\n", argv[0]); return 1; // Return an error code } int fd; fd = open(argv[1],O_RDWR | O_NOCTTY );//Open Serial Port int RTS_flag; RTS_flag = TIOCM_RTS; int DTR_flag; DTR_flag = TIOCM_DTR; // ioctl(fd,TIOCMBIS,&RTS_flag);//Set RTS pin // ioctl(fd,TIOCMBIS,&DTR_flag);//Set DTR pin // getchar(); ioctl(fd,TIOCMBIC,&RTS_flag);//Clear RTS pin ioctl(fd,TIOCMBIC,&DTR_flag);//Clear DTR pin close(fd); } nebo ``__ .. code:: #!/usr/bin/python -u # vim: fileencoding=utf-8:nomodified:nowrap:textwidth=0:foldmethod=marker:foldcolumn=4:ruler:showcmd:lcs=tab\:|- list:tabstop=8:noexpandtab:nosmarttab:softtabstop=0:shiftwidth=0 import serial import sys # Check if the correct number of command-line arguments is provided if not len(sys.argv) in {2,3}: print("Usage: {} [baudrate]".format(sys.argv[0])) print(" {} /dev/ttyACM0 - close USB Serial for Arduino on the port".format(sys.argv[0])) sys.exit(1) # Exit with a non-zero error code # Get the filename from the command-line argument baudrate=115200 filename = sys.argv[1] if len(sys.argv) > 2: baudrate=sys.argv[2] # Open the serial port ser = serial.Serial(filename, baudrate, xonxoff=False , rtscts=True , dsrdtr=True ) ser.rts=False ser.dtr=False * A ještě líp, použít `picocom -b $(SPEED) --flow n --noreset --hangup --quiet -s cat $(PORT);echo`, který tu linku uavře a `C-a` `C-s` se tam dá vložit soubor. (A netestovat nic, prostě `Serial.print("blabla");`) How to find out all #define used by arduino-cli in compile? -------------------------------------------------------------------------------- ``__ .. code:: make define: ## dump all #define to defines.dump @make |grep g++|grep .ino.cpp.o|sed "s/-o .*/-E -dM -o defines.dump/"|sh @sort defines.dump >defines.d @mv defines.d defines.dump @echo "defines.dump created"