2

I want to save the serial data from /dev/ttyUSB0 into a file (.txt) once I power on my Raspberry Pi. (Because I won't be connecting display or keyboard to Pi and I have to power off directly once my job is complete since I don't connect any display).

I tried to put these commands in /etc/rc.local before exit 0.

 sudo cat /dev/ttyUSB0 > file.txt & (using cat )

 sudo minicom -C file.txt &          (using minicom)

Nothing happens in both cases. No file is created.

Am I missing anything?

Can anybody suggest me any method for doing it?

Note: I'm using Raspberry Pi 2, Jessie

5
  • 2
    Hello and welcome. For starters: "->" is most likely wrong. Output redirection is just a >.
    – Ghanima
    Nov 22 '15 at 11:20
  • 1
    For minicom, well it's hard to tell as it uses a config file and we do not know the contents. Could be configure wrong, e.g. not using ttyUSB0 or a wrong baudrate and so on.
    – Ghanima
    Nov 22 '15 at 11:25
  • I used the same command by manually typing in command line, its works perfect. Only when I put it in /etc/rc.local nothing happens Nov 22 '15 at 13:40
  • And sorry about "->". It is not required as you said. Nov 22 '15 at 13:41
  • When you say “I have to power off directly once my job is complete”, are you shutting the Raspberry Pi down properly, or pulling the plug? The latter will result in your files getting corrupt.
    – scruss
    Aug 15 '16 at 20:00
1

Use grabserial. It's designed for logging serial information. You'd run it something like this:

grabserial -d /dev/ttyUSB0 -b 38400 > file.txt

You don't need to use sudo in rc.local. It's run as root anyway.

1

It seems that minicom doesn't work when run as background job. Had the same issue. I ended up launching a terminal at startup (using autostart & lxterminal) and letting it open while running minicom. To set it up :

  • sudo nano /home/pi/.config/autostart/minicom.desktop
  • paste this to open a terminal at startup and run a script

    [Desktop Entry]
    Type=Application
    Name=minicom
    Terminal=true
    Hidden=false
    Exec=lxterminal -e sudo /home/pi/startupscript
    
  • save and exit with ctrl+X

  • sudo nano /home/pi/startupscript
  • paste this minicom -b 230400 -D /dev/ttyUSB0 -C /home/pi/out.txt
  • save and exit with ctrl+X
  • reboot and you should seen the terminal opened with minicom running

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.