Is there a way to log events on Arduino when developing using C / AVR toolchain, and not the Arduino IDE? Working on Ubuntu.

  • Do you want your host system to record stuff received from an Arduino? Or do you want an Arduino to record data? Either way, the answer is yes, it can be done. Sep 7 '16 at 5:46
  • First one, I would like to see on my host what Arduino is doing.
    – vasily
    Sep 7 '16 at 7:16
  • The IDE uses a plain serial console to communicate with the Arduino. You can use any serial console application you like.
    – Gerben
    Sep 7 '16 at 7:55

On Ubuntu, I usually simply do

stty -F /dev/ttyACM0 raw 9600
cat /dev/ttyACM0 > the.log.file

Replace 9600 with your baud rate of choice.

  • Ha, neato. No character encoding mangling woes?
    – user400344
    Sep 7 '16 at 18:18
  • @user400344: The command is encoding agnostic: it moves the data from the serial port to the file as a byte stream, not a character stream. It could well be binary data for that matter. Sep 7 '16 at 19:26
  • Thanks, it will replace my terrible hack completely. Do you use something similarly simplistic to send data to your MCUs?
    – user400344
    Sep 7 '16 at 19:29
  • @user400344: No, I use text-based protocols, like in this command line interpreter, and type the stuff directly at the keyboard, usually through screen. You could cat the.data.to.send > /dev/ttyACM0 but, since the Arduino resets when you open the port, your sketch will miss the beginning of the file. You can avoid this auto-reset feature by putting a cap between RESET and 5V. Sep 8 '16 at 12:53
  • pretty neat. what value should I use for the cap?
    – user400344
    Sep 8 '16 at 16:45

Any of these are straightforward: python (serial library) or processing (same type of user interface, will happily build portable java programs for linux/win/mac). I use an awful perl script for logging stuff, can't recommend it. If you don't prefer the two first options, have a look at IPC::Open2 or IPC::Open3 - I use a bidirectional connection so I can send stuff, but I rely on 'tip' to do the serial connection stuff. If I wanted to log more than a few things, I would probably use python, which is much easier to read (later), and it will require a small fraction of the memory a fullblown java applet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.