Mix
Random mix of pages and files
Arduino
2023.08.24 03:20:17 end HowTo Gilhad

Arduino Serial až 2Mb/s (ale 115.200 je lepší)

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 (close_Serial.c)
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>

int main(int argc, char *argv[]) {
        // Check if the correct number of command-line arguments is provided
        if (argc != 2 ) {
                fprintf(stderr, "Usage: %s <filename>\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 close_Serial.py

#!/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: {} <filename> [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?

https://arduino.stackexchange.com/questions/94806/how-to-find-out-all-define-used-by-arduino-cli-in-compile/

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"