akmittra
Posts: 11
Joined: Wed Jan 18, 2017 1:03 pm

Need help with raspberry pi 2 usb to serial port communication

Sat Feb 17, 2018 5:50 pm

Hi. Currently, I am working on getting the raspberry pi 2 to communicate with my iboard avr via a usb-to-serial-port adapter cable for the main purpose of controlling the dc motors already connected to the iboard avr(atmega16). I have already installed the packages for avrdude and enabled the python serial port on rpi 2. However, I still have a few doubts:
1. Is there any test program for the usb-to-serial adapter connection without requiring another serial port to test with? The usb end is connected to the raspberry pi 2 and the serial port part is connected to the avr isp programmer tag of the iboard avr. Also, the rpi is able to detect the prolific usb-to-serial adapter when I type lsusb
2. There is still a program already active on the iboard avr. Via the usb-to-serial adapter, is there any way to erase that program by sending a command from the rpi via the said cable?
3. Can you provide any links for python programs that involve running dc motors using avrdude through usb-to-serial?

I am still open to other more feasible option of connecting the rpi to the iboard if you have any. In case if you are not familiar with the iboard model: https://www.indiamart.com/proddetail/ib ... 79173.html

I would really appreciate responses to these queries.

User avatar
scruss
Posts: 1775
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need help with raspberry pi 2 usb to serial port communication

Sat Feb 17, 2018 8:03 pm

Looks like you really want help with this, as you've asked already about this.

What does your USB to serial connector look like? Does it have a 9-pin connector like on the iBoard link, or does it look more like one of these USB to TTL Serial Cable - Debug / Console Cables?

Also, is there any documentation about your iBoard on the web? I can't find any at the link you posted. I'm sure you can program this board with avrdude, but without documentation, we're stuck.

You mentioned in your other post about trying to attach images: they need to be much smaller than the megabytes you mentioned. I think the limit's under 100 KB.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

akmittra
Posts: 11
Joined: Wed Jan 18, 2017 1:03 pm

Re: Need help with raspberry pi 2 usb to serial port communication

Sun Feb 18, 2018 4:14 am

Yes, it has a 9-pin connector like on the iBoard link. Here is a link of this particular cable:
https://www.aliexpress.com/item/MCT-U23 ... 08484.html. Regarding the iboard avr documentation, I do have a pdf available but I can't attach it here due to its size . Can you suggest how I can share it with you?

User avatar
scruss
Posts: 1775
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need help with raspberry pi 2 usb to serial port communication

Sun Feb 18, 2018 10:25 am

Cool. I've sent you my e-mail address via PM for the manual.

I'm fairly sure that this board will work like the old Arduino Severino serial boards. These can be more easily programmed via the Arduino IDE rather than using avrdude¹ directly. If your board has an ATMega8 on it, it only has ¼ the program memory that most Arduinos have, so a little care will be required.

What are you trying to measure with the iBoard and send back to your Raspberry Pi?

-------
¹: you can use avrdude if you want. It's just much harder to get the settings correct.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

akmittra
Posts: 11
Joined: Wed Jan 18, 2017 1:03 pm

Re: Need help with raspberry pi 2 usb to serial port communication

Sun Feb 18, 2018 11:32 am

For the time being, I want to be able to use the rpi 2 to control the dc motors already connected to the iboard using usb to serial communication, if possible. The board has an atmega16. I am still open to any other suggestions for communication between the iboard and rpi 2 for operating the dc motors. Are there any other connections I need to do besides usb-to-serial?

User avatar
scruss
Posts: 1775
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need help with raspberry pi 2 usb to serial port communication

Sun Feb 18, 2018 3:24 pm

Thanks for sending the manual(s) through. They are here: TRI AVR iBoard Guide and here: Think Labs Zed Guide.

Can you get the USB-serial adapter working? Plug it in, then in a terminal type lsusb - something like a serial adapter name should show up. If you're not sure, paste the text here.

Then, use dmesg to see the kernel messages for any serial ports. On my Raspberry Pi, this is the dmesg output that pertains to the USB Serial adapter:

Code: Select all

[    2.920149] usb 1-1.5.1: new full-speed USB device number 6 using dwc_otg
[    3.077701] usb 1-1.5.1: New USB device found, idVendor=0403, idProduct=6001
[    3.077712] usb 1-1.5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.077720] usb 1-1.5.1: Product: FT232R USB UART
[    3.077727] usb 1-1.5.1: Manufacturer: FTDI
 …
[    9.128046] usbserial: USB Serial support registered for FTDI USB Serial Device
[    9.128481] ftdi_sio 1-1.5.1:1.0: FTDI USB Serial Device converter detected
[    9.128809] usb 1-1.5.1: Detected FT232RL
[    9.129917] usb 1-1.5.1: FTDI USB Serial Device converter now attached to ttyUSB0
That's a long way of saying that the serial port is on /dev/ttyUSB0. You could see where yours is with ls -l /dev/ttyUSB*.

Do you know what program is already on the iBoard? It would be great if it already was one to control the motors over serial. I don't know much about avr-gcc development, and the iBoard is different enough from the Arduino that you'll hit problems if you assume they are identical.

I do know that you'll need to install these packages for AVR development:

Code: Select all

sudo apt install avrdude avrdude-doc binutils-avr avr-libc gcc-avr
As to the details of raw avr-gcc serial programming … that's beyond me. Some random googling turned up: One thing about the iBoard that's better than Arduino but different enough that it'll cause serial problems unless you know about it: the iBoard uses a 11.0592 MHz clock crystal, where an Arduino uses a 16 MHz crystal. You need to know the clock speed for serial programming, and the speed used on the iBoard gives much better serial port accuracy than the Arduino's one. 11059200 Hz divides exactly by 9600, 19200, ... standard baud rates — so whoever designed the iBoard knew what they were doing.

BTW, the Zed board doesn't appear to have a standard serial port at all, and you'll need to use a USB AVR programmer.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

akmittra
Posts: 11
Joined: Wed Jan 18, 2017 1:03 pm

Re: Need help with raspberry pi 2 usb to serial port communication

Mon Feb 19, 2018 8:24 am

Do I also need to make any gpio connections between the two boards?

User avatar
scruss
Posts: 1775
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need help with raspberry pi 2 usb to serial port communication

Tue Feb 20, 2018 1:38 am

No: different logic levels will cause problems. You can do all the comms you need over serial, and that's via the USB converter.

Over e-mail, you asked:
Regarding the program on the iboard avr, it is a program for a hand-gesture controlled robot. In order to be able to use the iboard for my current objective, I need to erase the program from the eeprom of that chip. Is there no way to send a command to flash or erase the program from the iboard with the set-up I have described via the avr isp programmer? Also, since you are aware of the setup, how can I truly test the usb-to-serial connection without requiring communication with a second serial port? The pi already has the avrdude libraries that you suggested.
I didn't know you had an AVR ISP — it would have saved me a lot of time. The command to erase the chip would be something like

Code: Select all

avrdude -c avrisp2 -e
You'd probably need to specify the chip type too. All of this is in the AVR programming book I mentioned, and also here: AVR Tutorial - AVRDUDE
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

akmittra
Posts: 11
Joined: Wed Jan 18, 2017 1:03 pm

Re: Need help with raspberry pi 2 usb to serial port communication

Wed Feb 21, 2018 1:15 pm

Hi,

As instructed, I tried the command: "avrdude -c avrisp2 -e -p m16" but it gives me this error: avrdude: usbdev_open(): "did not find any USB device "usb" (0x03eb:0x2104)
avrdude done. Thank you." Can you tell me what I am doing wrong? Also, on further inspection, the chip is an ATmega16A PU 1112. Does that mean the part no. is something else?

User avatar
scruss
Posts: 1775
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need help with raspberry pi 2 usb to serial port communication

Thu Feb 22, 2018 3:45 am

my mistake: it's not an avrisp you have, but something that plugs into the serial port. You might have to get help from ThinkLabs on this, as I'm guessing it's one of avrdude's siprog or ponyser programmers. You'll also need to set -m m16 to select your ATMEGA 16.

So the command line might be something like this:

Code: Select all

avrdude -c siprog  -P /dev/ttyUSB0 -e -p m16 -U lfuse:w:0xff:m -U hfuse:w:0xc9:m 
I guessed the fuse settings from the manual you sent, and plugged the values into this Engbedded AVR Fuse Calculator.

I really don't know what to suggest if this doesn't work.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

akmittra
Posts: 11
Joined: Wed Jan 18, 2017 1:03 pm

Re: Need help with raspberry pi 2 usb to serial port communication

Fri Feb 23, 2018 9:57 am

As instructed, I tried both siprog and ponyser and got the following results:
1. avrdude -c ponyser -P /dev/ttyUSB0 -e -p m16 -U lfuse:w:0xff:m -U hfuse:w:0xc9:m -F
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.10s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.09s

avrdude: Device signature = 0x000102
avrdude: Expected signature for ATmega16 is 1E 94 03
avrdude: erasing chip
avrdude: AVR device not responding
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | | 0% 0.00s ***failed;
Writing | ################################################## | 100% 0.23s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xff:
avrdude: load data lfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0x14 != 0xff
avrdude: verification error; content mismatch

avrdude: safemode: Verify error - unable to read lfuse properly. Programmer may not be reliable.
avrdude: safemode: Verify error - unable to read lfuse properly. Programmer may not be reliable.
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode

avrdude done. Thank you.

2. avrdude -c siprog -P /dev/ttyUSB0 -e -p m16 -U lfuse:w:0xff:m -U hfuse:w:0xc9:m -F

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.08s

avrdude: Device signature = 0x1e9403
avrdude: safemode: Verify error - unable to read lfuse properly. Programmer may not be reliable.
avrdude: safemode: To protect your AVR the programming will be aborted

avrdude done. Thank you.

In both options , I had to include -F to override the signature check otherwise, I was getting this:
avrdude -c ponyser -P /dev/ttyUSB0 -e -p m16 -U lfuse:w:0xff:m -U hfuse:w:0xc9:m

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
Overall, the problem now seems to be with reading the lfuse for some reason. Any thoughts?

User avatar
scruss
Posts: 1775
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need help with raspberry pi 2 usb to serial port communication

Sat Feb 24, 2018 2:16 am

Looks like you've got the programmer communicating with the chip. Yay! That's the Raspberry Pi bit done.

I'm guessing that the MCU might have the lock bits set. They can only be reset with a high-voltage programmer. This is now way out of my league, and way off this board's topics. Please ask on an AVR forum: the problem you have now is nothing to do with Raspberry Pi
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

akmittra
Posts: 11
Joined: Wed Jan 18, 2017 1:03 pm

Re: Need help with raspberry pi 2 usb to serial port communication

Wed Mar 07, 2018 12:48 pm

Hi. After several attempts, I have inadvertently erased the program that was on the iboard avr. However, I have to come to realize that all I wanted to do was connect my raspberry pi to the avr board simply to access its motors(M3 and M4) and nothing else, since the board already had a motor driver attached. Never really intended to use avrdude for my project in the first place. The robot control program that I have been assigned to work on for this setup is anyway in python. So, since you are familiar with the avr kit I am using, can you please suggest any GPIO-based connections between the rpi 2 and avr board or any other connection alternatives that do not require that ponyser programmer at all such that raspberry pi is one in complete control of the motors and the avr board is simply just a where the motor driver and dc motors are situated?

User avatar
scruss
Posts: 1775
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Need help with raspberry pi 2 usb to serial port communication

Wed Mar 07, 2018 4:12 pm

akmittra wrote:
Wed Mar 07, 2018 12:48 pm
So, since you are familiar with the avr kit I am using …
I'm not, I'm afraid. All I did was read the manual.
I'd recommend contacting the original supplier.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “Troubleshooting”

Who is online

Users browsing this forum: jamesh, nouranahmad, PhilE, salvato and 33 guests