Cant access AMA0 serial ports - linux/Raspberry pi

Status
Not open for further replies.

steeley

Well-known member
Got 3 teensy 3.5 connected to an RPI 3. I cannot get non-root access to AMA* serial devices devices.
ACM devices seem ok - this is if I plug a USB hub in and run Teensy 3.5 from there.

However, I need to connect the Teensys direct to the PI as there is no space in the setup for a hub.
I've tried everything I know, dialout groups, putting AMA* device in the udev file, which does nothing.

Looks like ACM* devices are always root only on PI:
crw-rw-rw- 1 root dialout 166, 0 Oct 30 17:10 /dev/ttyACM0
crw--w---- 1 root tty 204, 64 Oct 30 17:10 /dev/ttyAMA0

changing the permissions doesn't work, because it get overwritten on reboot.

Any idea how to fix this?
I have a big demo tomorrow, and if I can't get it working I'm stuffed. :(

TIA
 
Any idea how to fix this?

The normal way is to create a udev rule file.

Maybe this can help:

https://www.raspberrypi.org/forums/viewtopic.php?t=87510

The rule can set the mode to 666 (read/write permission for everyone) as Teensy's does. Or it can do things like assign the group to be "dialout" and then you make sure your user account is in the dialout group. Udev rules are very flexible, which makes there's a lot of permutations.
 
Thanks Paul - I have the dev file from your site and I'm using it as show below, but it doesn't work:
I tried that alternate install script, that doesn't work either.

# UDEV Rules for Teensy boards, http://www.pjrc.com/teensy/
#
# The latest version of this file may be found at:
# http://www.pjrc.com/teensy/49-teensy.rules
#
# This file must be placed at:
#
# /etc/udev/rules.d/49-teensy.rules (preferred location)
# or
# /lib/udev/rules.d/49-teensy.rules (req'd on some broken systems)
#
# To install, type this command in a terminal:
# sudo cp 49-teensy.rules /etc/udev/rules.d/49-teensy.rules
#
# Or use the alternate way (from this forum message) to download and install:
# https://forum.pjrc.com/threads/45595?p=150445&viewfull=1#post150445
#
# After this file is installed, physically unplug and reconnect Teensy.
#
ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789B]?", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789A]?", ENV{MTP_NO_PROBE}="1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789ABCD]?", MODE:="0666"
#KERNEL=="ttyAMA*”, ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789B]?", MODE:="0666"
#KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789B]?", MODE:="0666"

KERNEL=="ttyAMA*”, MODE:="0666"
KERNEL=="ttyACM*", MODE:="0666"

#
# If you share your linux system with other users, or just don't like the
# idea of write permission for everybody, you can replace MODE:="0666" with
# OWNER:="yourusername" to create the device owned by you, or with
# GROUP:="somegroupname" and mange access using standard unix groups.
#
#
# If using USB Serial you get a new device each time (Ubuntu 9.10)
# eg: /dev/ttyACM0, ttyACM1, ttyACM2, ttyACM3, ttyACM4, etc
# apt-get remove --purge modemmanager (reboot may be necessary)
#
# Older modem proding (eg, Ubuntu 9.04) caused very slow serial device detection.
# To fix, add this near top of /lib/udev/rules.d/77-nm-probe-modem-capabilities.rules
# SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", GOTO="nm_modem_probe_end"
#
 
You could also try running your program with sudo, so it has root permission. Not great security practice... but if it works you can at least get through the demo tomorrow.
 
just thought of that... it'll do for now I guess.
I tried a Teensy LC too, and that didn't work either....

I've looked at a few RPI threads on this subject, and there are various hacks, some of which work with Arduino.
what I've tried from these suggestions doesn't work with Teensy though.
 
Just to be clear, those /dev/ttyAMA ports are Raspberry Pi's hardware. They're the serial pins on the 40 pin header. If you're programming Teensy to communicate on Serial1, Serial2 or Serial3 and you've connected those serial pins to the correct places on 40 pin header, then the /dev/ttyAMA device is what you need.

But if you're using USB, that /dev/ttyAMA will do you no good at all. It controls the serial pins on Raspberry Pi's 40 pin header.
 
Yes I wondered about that - it seems my Teensy when plugged in shows up as an AMA device, which is clearly not correct.
 
Here's a blind guess... maybe you're writing code to talk to the port, rather than using the Arduino Serial Monitor?

A common problem people encounter is the "line discipline" setting. You need to turn this off, especially if sending non-ascii data. If programming in C, you do this by calling tcgetattr() to fetch the port's settings, then cfmakeraw() to configure for raw mode, then tcsetattr() to write the settings to the port.

If you use the Arduino Serial Monitor, this setting is automatically turned off by the Arduino software when it opens the port. So one possible "quick fix" is to first open the Arduino Serial Monitor, and close the window. Then try opening the port from your program after Arduino has opened it once (and turned off the line discipline settings)
 
Last edited:
Ok I don't know whats going on now - I tried Arduino + teensyduino and that didn't work, although an Arduino mega was ok.
Tried running terminal gun prog. Cutecom as root, and I can open the teensy port but can't seem to write to it.

I could do this without root access and it all worked fine when I used a USB hub. now its completely screwed.
not sure what line discipline has to do with Serial port permissions.
I don't see why teensy has a problem yet Arduino and other serial devices I have tried are all fine.
I may have to reinstall raspbian again and start from scratch which is not what I need right now.
 
First, double check you have installed Teensy's udev rule file. Earlier I assumed you had done this, because ttyACM0 was giving you permission to use it. But maybe something else is causing that?

This is the udev rule file:

https://www.pjrc.com/teensy/49-teensy.rules

You *MUST* have this file in /etc/udev/rules.d/49-teensy.rules on your Raspberry Pi.


When that file is in place, physically unplug and reconnect your Teensy. Any changes to the file take effect the next time you plug in the USB cable.

If things aren't working, I recommend you run something like this on the Teensy:

Code:
void setup() {
}
void loop() {
  Serial.println("hello world");
  delay(100);
}

After uploading, make sure you have the correct Port selected in Tools > Ports. Open the Arduino Serial Monitor. You should see the "hello world" printing. Get this working first, before you move on to other programs.
 
Thanks - will install from scratch for a clean start , although I did go through the process you mentioned before,
I'll see if it works this time round.
 
Why not just try the "hello world" first with Arduino's serial monitor? Or maybe you already did that and it didn't work?
 
Installed a fresh Raspberry pi system and without any Arduino IDE, Teensyduino, dev etc etc
I can see Teensy boards as ACM0, 1 etc and can read and write to them. That will have to do for now.

I don't really need to run an IDE but it would be nice to be able to flash the teensy from the PI.

Is it possible to get the Teensy name like usbmodemXXX ? - otherwise its hard to distinguish each Teensy
if they get plugged into. different USB ports without some extra software.

Why not just try the "hello world" first with Arduino's serial monitor? Or maybe you already did that and it didn't work?
 
Is it possible to get the Teensy name like usbmodemXXX ? - otherwise its hard to distinguish each Teensy
if they get plugged into. different USB ports without some extra software.

Every Teensy 3.x board has a unique serial number. The udev rules are very flexible with many features, including ways to assign different names or to automatically create symbolic links based on properties like the serial number. But with so much power and flexibility, like so many things in Linux, it comes with quite a bit of complexity. I personally have not done this, so I can't help much, other than to tell you I've seen this feature documented while creating the udev rule file we publish for Teensy. I'm sure with some searching you'll find lots of documentation on the Linux udev rules.
 
I don't really need to run an IDE but it would be nice to be able to flash the teensy from the PI.

Is it possible to get the Teensy name like usbmodemXXX ? - otherwise its hard to distinguish each Teensy
if they get plugged into. different USB ports without some extra software.

As Paul mentioned, you can do it with UDEV rules. I have done it in the past, where I create symbolic names for some tty like devices so my Linux code can open up device names, like:
/dev/ttyXBEE and /dev/ttyDXL looking for the XBee and the Dynamixel device...

I always have to look it up on how to do it, and I kept some of my notes about this in the Readme.md file for the github project: https://github.com/KurtE/Raspberry_Pi
If you look for the section: Setup tty Device on RPI

In there is a link to: http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/ which helps me when I am trying it out.

Example in my read me is setting up links to FTDI devices, where I had a file: /etc/udev/rules.d/99-usb-serial.rules that contained:
Code:
    SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A800fclo", SYMLINK+="ttyXBEE"
    SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A4014UWE", SYMLINK+="ttySSC-32"
Note the vendor was for FTDI, the Teensy will be different...
 
Status
Not open for further replies.
Back
Top