I'm a totally newbie and interested in physical programming like raspberry pi's. Is there any way to get the data which is intended to go to a "USB to TTL converter device" through USB(e.g. the output of a flashing software), read it and convert it to TTL using Python or C language? I mean something like:
Compiler --> avrdude --> Ethernet port of the compiler host PC --> Ethernet port of a Raspberry Pi --> Pins of the Raspberry Pi --> avr microcontroller
My question is about the code which I should run on the Raspberry Pi to do all the work required on that side. I'm guessing in this specific example it's possible to install avrdude on the Raspberry Pi and pipe the compiled code from the PC to the avrdude on the pi but I'm looking for a general solution that can be used with all microcontrollers, essentially turning the Raspberry Pi into a transparent, Ethernet connected, USB to TTL converter, either existing libraries or directions to how to write such code and where to read the documentations.
Edit1: There's a C language library called pigpio already installed on the Raspberry Pi OS and it can output UART. But I don't know how to read the USB data coming to the Raspberry Pi through its Ethernet port and convert it to UART data.
Edit2: I Changed USB port to Ethernet port since you can't connect two computers directly through USB. The data coming from the PC is still intended for USB to TTL converters since that's how avrdude and similar softwares are written(I guess it'll be "USB over Ethernet").
Related
Raspberry Pi model: 3B
Running Raspbian OS
Recently I bought a Hyperpixel 2.1 round, which uses all of the GPIO ports. Whenever I plug the Raspberry Pi into my network switch, it is unable to connect to the network with the Hyperpixel attached. However, when I removed the Hyperpixel, the Ethernet capability came back.
I'm fairly sure it's a software issue given that there shouldn't be any problems with running all gpio pins in addition to Ethernet.
Is this a quirk with the Raspberry Pi that it doesn't like having all GPIO ports occupied as well as Ethernet? And how would I potentially go about fixing this, perhaps through command line or in the boot config?
I'm working on a project where I need two raspberry pis to communicate and the ethernet port is not free, I'm not allowed to make any changes to the GPIO pins, and I'm forced to use the USB port due to hardware considerations. Is it possible for them to communicate using a direct USB cable, or perhaps using two USB-RS232 cables?
Thanks!
Siddharth
I would use the TTL serial pins on the GIO header. See https://elinux.org/images/1/13/Adafruit-connection.jpg
You could create your own simple null modem serial cable - consisting of 3 jumper cables.
Connect pins
6 <--> 6
8 <--> 10
10 <--> 8
If you can't use the GPIO header - you can do a USB to USB connection using USBNET. http://www.linux-usb.org/usbnet/
Is it possible for them to communicate using a direct USB cable, or perhaps using two USB-RS232 cables?
You fail to mention exactly which Raspberry Pi version(s) you are using.
Only the Raspberry PI Zero can be used as a USB Gadget.
Since USB is a master-slave(s) interface & protocol, you cannot simply connect two Raspberry PI 1/2/3 boards together using USB, because that would be a master-to-master connection.
If you look hard enough for a (passive) USB Type A (male) to Type A (male) cable, you can find them, but it's a bogus connection that will not work.
There are active USB host-to-host cables (which contain a shared gadget), but support can be an issue.
You could connect a Raspberry PI 1/2/3 to a Raspberry PI Zero by USB, so long as the Zero's USB port was configured as a USB ACM CDC gadget.
However one simple solution is your alternative of installing USB-to-RS232 adapters to each board. A null-modem cable of three wires would suffice unless you needed hardware flow-control.
An alternative solution is installing USB-to-Ethernet adapters to each board (with static IP addresses, i.e. an ad-hoc connection). This approach provides a much faster connection than an RS-232 link, and is easily utilized by applications.
I want to install MATLAB and Simulink support package for Raspberry Pi. I follow this link to do . I directly connect my laptop with Raspberry Pi using Ethernat cable.
But i didn't get output.
while installing i got error - "Could not detect a Raspberry Pi board on "Local Area Connection". Check your Ethernet connection to Raspberry Pi.
The FDX/LNK/100 LEDs on the Raspberry Pi board should be illuminated.
For network trouble-shooting instructions see http://www.mathworks.com">The MathWorks Web Site"
Can anyone help to solve this problem?
I have also experienced your same issue but after proceeding in this way I solved it.
Before you put the SD card on the Raspberry Pi you need:
power off the Pi
connect the Ethernet cable to the host computer
finally power on the Pi
In addition you may take a look at this troubleshooting guide.
Try the following steps.
1. Open cmd and execute 'ipconfig'
check for a network interface with '169.x.x.x' ip address
If there is one, you could access your Pi via IP 169.254.0.2
If there is none, check if your Ethernet port is enabled and no static IP is configured.
The above steps make sure that your Ethernet port is in proper state.
Repeat the hardware setup with direct connection in the network settings.
I bought a new Arduino Ethernet Shield and hooked it to the Arduino Uno.
I am trying to set the IP address of the device to 192.168.1.177 tried File-> Examples -> Ethernet-> Webserver.
When I upload this - I get a "server is a 0.0.0.0'message in serial monitor !
My IP is set to 192.168.1.177 and setup a mac address of 0xB8, 0x27, 0xEB, 0x98, 0x46, 0x61 in the webserver code.
Appreciate any help in setting this IP address. ( I tried other combinations as well )
The Arduino Ethernet shield is mounted on the Arduino Uno, and connections are lined up .
i fix this problem by pressing firmly the shield to the board
This can manifest from many different causes. I ran into this and figured out that in my case, my the USB port + cable were not allowing sufficient power to the Ethernet chip.
I have 3 cables, 6in, 3ft, and 6ft. Only the 6" one had sufficiently low voltage drop to power the shield.
I honestly couldn't believe it, but there was a 0.1V drop between the 6in and the 6ft cables. When plugged into A USB 3.0 port with the Arduino loaded, I measured ~4.5V for the working 6in cable vs ~4.4V for the non-working 6ft cable.
I have 3 types of USB ports: 1.1, 2.0, and 3.0. Only the USB 3.0 ports provided enough power to power the shield. Thus for my case, I had to use the shortest USB cable on the 3.0 port.
When the Arduino's 5V rail was sufficiently sagging, the 3.3 Linear Regulator entered dropout mode and on all the non-working configurations I saw ~3.1V on the Ethernet shield's 3.3V rail, which is apparently sufficient to cause this symptom.
How can we do serial communication using the raspberry pi with a python script to send/receive data to my laptop? If yes can we use the RS232 cable to connect to the TX/RX ports on the raspberry pi directly? If yes, what pins must be used from the RS232 cable? It would be help full if anyone can post a example python script?
Since my first aim is to send/receive data to the laptop to/from the raspberry pi, i'm using a RS232 to USB cable at both end to connect to the laptop as well as the raspberry pi.
RS-232/RS-485 to PC and USB to PC
For RS-232
1) Download Putty.
2) Buy a Serial Port RS232 to TTL Converter Module and a RS-232 serial cable for PC.
3) Follow the steps in Connection to a microcontroller or other peripheral on this
link. Actually read the whole thing for better understanding.
4) Power your converter module with either 3.3V (pin 1) or 5.0V (pin 2), connect Rxd pin of the module to Rxd (pin 8) on Rpi and Txd pin to Txd (pin 10) on Rpi.
5) Connect your RS-232 (from PC) cable to the converter module
Now you are ready to do some coding in Python. But before that make sure that you have the library called serial for python to create the communication. You can easliy get it via terminal by typing sudo apt-get install python-serial. Also you will see the baudrate in the code is 7200. It could be less or more depending on the synchronization. Also make sure that baudrate should be same in putty and COM1, which is the port that RS-232 is connected to your PC. You can check and set it from device manager in Windows. By the way, timeout is the time gap between each message you are receiving.
In case you can't run the code from idle (that happens for some libraries), do it in terminal. For that go to the folder where you keep your python code and type python name.py.
import serial
import time
def readlineCR(port):
rv = ""
while True:
ch = port.read()
rv += ch
if ch == '\r' or ch == '':
return rv
port = serial.Serial("/dev/ttyAMA0", baudrate = 7200, timeout = 2)
while True:
rcv = readlıneCR(port)
port.write("I typed: " + repr(rcv))
print(rcv)
For USB serial to PC
You have two options
First, you can buy a USB dongle for RS-232/RS-485 so that you would not use GPIO pins. But it is better to get a USB hub for all mouse, keyboard and dongle.
Second and easier, you can buy a FTDI USB to TTL converter and use GPIOs to have a serial communication with Rpi. The code for this is exactly the same the one with above. Connection for this is easy.
Module -- Rpi
Txd -- > Txd
Rxd -- > Rxd
Gnd ---> Gnd
Are you trying to issue commands to the Raspberry Pi? (like a console?) I would suggest a plain jane 3.3V FTDI cable. You can get them from Digikey or Sparkfun. Note: the Raspberry Pi runs on 3.3V so you must be sure that anything you connect to it is running 3.3V or has a level shifter. See more information about level shifters here. (go down to the Logic voltage levels section)
First, you need to make sure that Raspbian has released the serial console. You can do that with the script located here.
If you're more interested with communicating with other devices then maybe the following suits you:
Do you have an Arduino? You can run a simple test by putting this sketch on your Arduino:
#define SERIAL_BAUD 115200
void setup() {
//Init serial connection
Serial.begin(SERIAL_BAUD);
Serial.setTimeout(1);
}
void loop() {
if ( Serial.available() ) {
byte type = Serial.read();
Serial.write(type);
}
}
And wire it up using the following diagram:
Note: make sure you don't connect a usb cable to the Arduino. It will be powered by the Raspberry Pi.
You can then install and run screen. Screen is a dead simple way of connecting to a serial port.
apt-get install screen
Then run the following:
screen /dev/ttyAMA0 115200
The screen will show up blank. But, when you start typing you will notice that the characters you're writing are getting looped back to your terminal.
Note: If the screen is still blank you should double check the connections (power led on the Arduino is a good thing to check).
When in doubt you can see my whole example here.
The Raspberry Pi's serial port uses 3.3v logic; RS232 uses 12v, so a level shifter would be needed to use those pins so you cannot use RS232 directly.
Serial interfacing in Python using the PySerial module (http://pyserial.sourceforge.net) it is pretty straightforward to send and recieve data. There are examples in the documentation, but essentially to send data:
import serial
port = serial.Serial(portname, baudrate, timeout)
port.write("message to send")
port.close()
It depends what you're doing with the data and what sort of data you're recieving to decide the best way to recieve data, but a very simple example:
import serial
port = serial.Serial(portname, baudrate, timeout)
data = port.read(numberofbytes)
print data
This simply waits until the number of bytes specified has been retrieved or the timeout value is reached.
You can use port.inWaiting() to return how many bytes are currently in the buffer.
you should install python library for serial drivers. you can not use rs232 directly, instead you can use a max232 chip in between rx(gpio15) tx(gpio 14) pins and your usb to serial converter. or you can use usb to ttl serial cable from adafruit. here is the link for setup : http://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/overview
Serial Communication in Raspberry pi.
There are plenty of options for serial communication
Use Visual GDB Plugin in visual studio and deploy code remotely in raspberry pi
and loop back the txd and rxd pins and check if the send message is received or not.
If you are familiar with java Install pi4j and in the example folder there is a sample program , compile and run using terminal. and check the output.
if you are connecting using RS232 and Max232 , please note that uses 3.3 volt not 5 or 12v. , it may burn your board.