Raspberry PI Pico USB Connection Issues when configuring/setting up ports - c

I am using the USB port of the Raspberry Pi Pico as my debug port when running C programs on the Pico. I have noticed that sometimes when I connect to the Pico USB using Putty in serial port mode, it takes forever (at least 5min) to connect and display the Putty terminal window. I have done the following to eliminate this issue:
Multiple reboots of the Pico before I am able to connect immediately.
Removing Pin configuration and initialization code eg: gpio_init(2); gpio_set_dir(2, GPIO_OUT); and so on. I noticed when doing this I connect immediately. Put this code back and I am back to waiting 5min for Putty to connect or resetting the device multiple times.
Does anybody know why this is happening?
Many Thanks.

Related

Replace a printer with a pc using serial port

I have to update my question (May 4th). The male db25 connector misled me to the parallel port so I rephrased it.
I have an old computer system that sends live data (temperature from some external devices) to a parallel dot printer. This computer must not be changed.
Instead of printing I would like to connect the printer cable in an (ubuntu os) pc serial port in order to receive those data and redirecting them in stdout.
Checking the db25 pins I discovered that it is used as RS232 serial cable. There are only three pin connected:
pin 2 (TXD)
pin 3 (RXD)
pin 7 (GND)
So my intentions are firstly to connect those pins to a db9 serial connector in order to plug it in a pc serial port and secondly to open and read the input data using:
chmod o+rw /dev/ttyS0
cat -v < /dev/ttyS0
I believe that it is a simple solution and it is going to work.

Bluetooth Low Energy - Linux with BlueZ

I'm working on a project where I need to establish connection between my computer and a Adafruit feather 32u4 with BLE incorporated.
Due to comments on lots of webs, I decided to use linux to do the job.
I got everything installed and I can connect my BLE with the PC successfully.
----MY CONNECTION PROCEDURE-----
I can even recieve data and send data between them with gatttool.
To connect both devices i use this commands:
sudo hcitool lescan
sudo gatttool -t random -b F6:E5:F4:A7:71:E6 -I
connect
The devices are connected correctly. I can use all the gatttool commands and they respond as expected.
----END OF CONNECTION PROCEDURE----
---MAIN PROBLEM---
I don't know how I could implement all the commands in a packed C program.
I need to be able to manage all the commands in the same program !! without using brute force with system().
It would be great if someone could show me how gatttool do its magic.
I mainly need to know how to get the data from Rx and how to send it to Tx via code not commands.
Note: I can supply any further information if needed.

Is client connected on XBee s6b

I have an XBee S6B setup in wireless access mode and physically connected to a Raspberry PI. I connect my laptop to the XBee WiFi access point and I can send data back and forth between the Raspberry PI and the XBee over WiFi.
Can someone tell me if there is a way for the Raspberry PI to know that the laptop has successfully connected or disconnected? Are there any commands the Raspberry PI can send to the XBee to establish if something has connected/disconnected?
There’s no Node Join frame, but if it’s in Access Point mode then you could just periodically ping the other device. You would know its address since there can’t be more than one external device in AP mode.

Disconnecting Monitor From Raspberry Pi while Running Script

I currently have a C script on the Pi that controls a spectrometer (through a USB input) and a servo motor through the GPIO pins on a Raspberry Pi. The program requires a few user inputs, so I need a monitor connected to start the program. However, I may be needing to run this script for a while, so I need to unplug my laptop once the script is running. Right now, when I unplug my laptop, the script stops running, but it is fine to run as long as I ask it to when I keep the laptop hooked up. Any advice on how to remotely run a script that still requires a user input in the terminal window?
You could get the IP address of the Pi using ifconfig and remotely log into it from a different computer and run the script remotely
Use utilities like screen or tmux. They will be available through your package manager.

Serial Port Connection Between Host and Guest with Virtualbox

I'm trying to learn how to write C code that will read from the serial port in Linux. I've found what seems to be a good tutorial here.
I want to be able to test this code, so I think I need either a serial port, or a way to write to the serial port while the code from above is reading.
I'm running Ubuntu 10.04 as a virtual machine on my Mac using virtualbox. My idea was to set up a virtual serial connection and write from the host to the guest. Hopefully something as simple as cat "Hello World" > /tmp/fake_serial in a host terminal, and for that to be read by the program in the link above.
Is this possible? I've tried adding a serial port using virtual box and when I try to do the above command I get an error saying I can't write to a socket.
The second option I thought of was using something like minicom inside the guest OS, to connect to say /dev/ttyS1 and write messages for my code to read at the same time. Again, assuming that the baud rates and other settings are OK, would this be possible?
I don't have a lot of experience working with serial ports, so I'd appreciate any suggestions about the best way to do this. Thanks in advance.
So to get this working I just added another Ubuntu VM on VirtualBox, and connected the two together via a virtual serial port. My main, original VM, which I use for a lot of developing will be referred to as VM1. The new VM, with a small hardrive that will only be used for sending messages to VM1 will be called VM2. These are both Ubuntu 10.04 VMs.
In VirtualBox go to Settings for VM1, go to ports, and change the settings as follows:
Now go to VM2, and select settings, ports, then change as follows:
Now first you need to start VM1. When that's booted then boot VM2. Now you can open a terminal in VM1, and type screen /dev/ttyS0 38400 (you may need to run sudo apt-get install screen before this works). Then go to VM2, open a terminal, and type echo "Hello" > /dev/ttyS0.
You should see Hello appear in the terminal open in VM1. When you're done running screen press ctrl-a k to kill it, otherwise if you try to do other stuff with the serial port you may get an error message saying that the port is busy.
When I had to do some serial port testing from my real to virtual machine I ended up doing a "loop back" type testing. I took two USB-Serial converters and a RS232 F-F adaptor and connected my machine to itself. Then in VirtualBox under Settings->USB you can route one of the two USB-Serial converters to be "owned" by your VirtualBox.
Once you plug in the converters one will register with the Mac and one with the Ubuntu "computer" then you can do serial communication as normal between the two machines.
You may also be able to emulate a virtual serial port using a pty ("pseudo-teletype" device), but I'm not positive on that one since I believe the ability to do that was locked down in newer kernels.
I ran into a similar situation running a QNX guest using VirtualBox 5.0.10 on an Ubuntu 14.04 host.
My solution seems general enough to apply to the above-mentioned case.
I configured the guest VM in the same way that Kells1986 setup his VM1:
Under the "Serial Ports"/"Port1" tab:
check "Enable Serial Port"
set "Port Number" to "COM1"
set "IRQ" to "4"
set "I/O Port" to "0x3F8"
set "Port Mode" to "Host Pipe"
uncheck "Connect to existing pipe/socket"
set "Path/Address" to an accessible file-system path (e.g. "/home/safayet/vmSerialPipe")
According to the VirtualBox manual:
You can tell VirtualBox to connect the virtual serial port to a
software pipe on the host. ... On a Mac, Linux or Solaris host, a local domain socket is used ... On Linux there are various tools which can connect to a local domain socket or create one in server mode. The most flexible tool is socat and is available as part of many distributions.
A domain socket is an IPC mechanism on UNIX systems similar to a pipe.
I connected to the "pipe" end of the virtual serial port on the Ubuntu host using the socat command:
socat - UNIX-CONNECT:/home/safayet/vmSerialPipe

Resources