PIco W: is there a way to detect if usb power is connected in micropython? - gpio

I am trying to detect (ideally fire an interrupt) when a usb host is connected and supplies 5v. (in this design i have a separate "always on" Vsys supplied from another source).
According to the schematics in https://datasheets.raspberrypi.com/picow/pico-w-datasheet.pdf it would be possible to know this by reading the state of the WL_GPOI2 pin. Unfortunately this pin is actually located on the CYW43439 wifi chip.
The green led on the board (connected to WL_GPOI0) is trivially accessible by using the below so it seems possible to get to the GPIO on the wifi chip.
from machine import Pin
led = Pin("LED", Pin.OUT)
Is there a way of reading the WL_GPOI2 pin or otherwise finding out if a usb cable is connected?
ideal would be to fire an interrupt, but polling a status would also work.

Related

Reading signals on ethernet port directly with RaspberryPi

I have a device which connects to its remote using rj45 port and 4 wire cable (a desk with adjustable height). I'm pretty sure it does not actually use an Ethernet protocol and uses sends some simple digital signals.
I want to Raspberry Pi to be able to control the device, so I was wondering if it is possible to read and dump and then send signals using Ethernet port just like I can do with any other pins? Probably the actual question here is about a way to bypass Ethernet driver in Linux OS.
This won't work. The Ethernet NIC on the RPi - just like any other NIC - can only receive Ethernet frames. Anything else needs to be connected over GPIO.
Edit: As NO-OP has reasonably pointed out, the signals may need to be made compatible with the GPIO pins - levels adjusted, maybe an opto-isolator here and there. Nothing expensive though usually. For controlling powered devices you likely need a driver or relais board - there are plenty around for the RPi.

How to use APC220 Radio Communication Module in raspberry pi

I am developing a project using Arduino to send a message to Raspberry Pi using an APC220 Radio Communication Module.
The Raspberry Pi can't receive serial message by using USB connect to APC220. I want to know how to use APC220 in Raspberry Pi?
The APC220 has a TTL UART interface which you can connect directly to the RPi TTL UART pins on the GPIO header - you do not need the USB-Serial converter (though that should work too if it is a standard CDC/ACM device - though this suggests that there may be issues).
A note of caution however, the RPi GPIO pins use 3.3Volt logic, the APC220 datasheet is not clear on the TTL level used, but the specified supply range is 3.3 to 5.5 volts so it seems likely that it is 3.3V - best measure it to be certain. You can probably use the RPi GPIO headers's 3.3V supply pin to power the ACM220, then you will be sure to be safe. If the ACM220 level is too high, the quick-and-dirty solution is to use current limiting resistors in-line to protect the RPi (10KOhm should be enough, but don't hold me responsible; you should know what you are doing before proceeding).
The UART device on the Pi is /dev/ttyAMA0.
See here for details of serial I/O on the Pi.
22 Feb 2012 Update
The discussion here suggests that to make the TTL<->USB adapter work on Raspberry Pi, you need to disconnect the EN signal - the discussion links back to the manufacturer documentation, which gives that advice in the troubleshooting section. Since that makes the device appear as a USB serial, and you won't have to reconfigure the on-chip serial or build a connector that may be simpler.

How does Bluefruit EZ-link perform DTR/RTS over Bluetooth for programming?

Bluefruit EZ-link is described as programmer. It means it supports RTS/DTR:
The EZ-Link has another impressive feature: the DTR/RTS/DSR flow
control pins are automatically synced to the computer serial port.
What this means is that if the computer sets the hardware flow control
DTR or RTS pins high or low the pins on the bluetooth module will
follow.
So Arduino IDE performs reset to initiate flashing (as Arduino's Bootloader wait for few seconds after reset for upload commands from Arduino IDE). For USB reset works by switching DTR to 1 and 0 and special schematics on Arduino board monitors it and performs reset. After reset is done Arduino IDE runs avrdude and start flashing.
The question is "How does it works over Bluetooth module by Adafruit?" There is no RTS/DTR line for Bluetooth..
PS. I believe virtual COM-port drivers for this Bluetooth device should send special AT+ commands and Bluetooth device should handle them and perform setting 1 or 0 to special pin wired with MCUs reset. But this requires Bluefruit bluetooth driver to be used. But i can't see it requires special BT drivers at computer.
RFCOMM do support flow control.
RFCOMM is based on GSM TS 07.10. Bluefruit extract info on RFCOMM and map it to flow control lines.

Linux writing raw bytes on USB

I've got usb cable plugged to my computer, which D+ and D- pins are connected to multimeter. I want to send some raw bytes to get some voltage.. is it possible at all?
I'm 99% sure that usb port I've plugged cable in is something like /dev/bus/usb/002
I know that there was possibility to do the same with LPT or RS232 ports.
RS232 and LPT are not bus ! USB devices need to be addressed in order to become reachable.
Maybe unloading and reloading usb driver that drive your usb host... or trying to make a reset on usb hub host...
For doing this kind of operation on usb port, you have to break usb kernel driver and whipe all addressing operation to address directly the chipset...
At all, due to USB concept, I'm not sure you may successfully hold some power state on outlet.
For playing with that kind of physical IO, two solution:
Install a low-cost RS-232 <-> USB adapter
or better
Buy an Arduino micro-controller for prototyping and development.
I'm nearly 100% sure that you can't send anything down your USB lead unless you actually have a device at the other end. If you still want to play with this, get a cheap memory stick, break the casing off it [not too roughly], and measure whilst doing a large file-transfer to the memory stick, or some such.
But I'm not sure your multimeter will show much, as they tend to be a bit slow, compared to USB rates.
USB uses pull-up / pull-down resistors on the data lines to detect whether or not a port is connected (1.5k pull-up to 3.3v on the device side, 15k pull-down on the host side IIRC). The exact connection depends on the device speed.
So if you connect an appropriate resistor, the host should attempt to start signalling. Because of the data-rate, you might not be able to see that on a multimeter; an oscilloscope would be more appropriate.
If you want to by-pass the normal USB protocol and just blindly send data, I think you'll need to get your hands dirty and write code to bypass the usual device drivers and access the USB hardware directly. Even then I'm not sure what's possible - the USB hardware is a lot smarter than good ol' LPT and RS232 ports, which might get in the way of doing this sort of low level stuff.

How to send keystrokes from one computer to another by USB?

Is there a way to use one computer to send keystrokes to another by usb ?
What i'm looking to do is to capture the usb signal used by a keyboard (with USBTrace for example) and use it with PC-1 to send it to PC-2.
So that PC-2 reconize it as a regular keyboard input.
Some leads to do this would be very appreciated.
What you essentially need is a USB port on PC-1 that will act as a USB device for PC-2.
That is not possible for the vast majority of PC systems because USB is an asymmetric bus, with a host/device (or master/slave, if you wish) architecture. USB controllers (and their ports) on most PCs can only work in host mode and cannot simulate a device.
That is the reason that you cannot network computers through USB without a special cable with specialised electronics.
The only exception is if you somehow have a PC that supports the USB On-The-Go standard that allows for a USB port to act in both host and device mode. USB-OTG devices do exist, but they are usually embedded devices (smartphones etc). I don't know if there is a way to add a USB-OTG port to a commodity PC.
EDIT:
If you do not need a keyboard before the OS on PC-2 boots, you might be able to use a pair of USB Bluetooth dongles - one on each PC. You'd have to use specialised software on PC-1, but it is definitely possible - I've already seen a possible implementation on Linux, and I am reasonably certain that there must be one for Windows. You will also need Bluetooth HID drivers on PC-2, if they are not already installed.
On a different note, have you considered a purely software/network solution such as TightVNC?
There is a solution:
https://github.com/Flowm/etherkey
This uses a network connection from your computer to the raspi which is connected to a teensy (usb developer board) to send the key strokes.
This solution is not an out-of-the-box product. The required skill is similar to programming some other devices like arduino. But it's a complete and working setup.
The cheapest options are commercial microcontrollers (eg arduino platform, pic, etc) or ready built usb keyboard controllers (eg i-pac, arcade controllers,etc)
SEARCH THIS PROGRAM:
TWedge: Keyboard Wedge Software (RS232, Serial, TCP, Bluetooth)
then, MAKE YOUR OWN CONNECTION CABLE WITH:
(usb <-> rs232) + (NULL MODEM) + (rs232 <-> usb)
Connect 2 computer, write your own program to send signal to your (usb <-> rs232) unit, then you can control another computer under the help of TWedge.
The above mentionned https://github.com/Flowm/etherkey is one way. The keyboard is emulated from an rPi, but the principle can be used from PC to PC (or Mac to Whatever). The core answer to your question is to use an OTG-capable chip, and then you control this chip via a USB-serial adapter.
https://euer.krebsco.de/a-software-kvm-switch.html
uses a very similar method, using an Arduino instead of the Teensy.
The generic answer is: you need an OTG capable, or slave capable device: Arduino, Teensy, Pi 0 (either from Rapberry or Orange brands, both work; only the ZERO models are OTG capable), or, an rPi-A with heavy customisation (since it does not include USB hub, it can theoretically be converted into a slave; never found any public tutorial to do it), or any smartphone (Samsung, Nokia, HTC, Oukitel ... most smartphones are OTG capable). If you go for a Pi or a phone, then, you want to dig around USB Gadget. Cheaper solutions (Arduino/Teensy) need custom firmware.

Resources