Using Yun bridge library on Raspberry pi - python

I am new here and this is my first post. I am not 100% sure where to post this. I think it is something on the OS level so I chose to post it here. Moderators please move it to the correct place if it does not belong here.
I am developing a controller to control a industrial type process. I started off using the Arduino Yun that is a all in one type board with a Linux processor and Arduino controller on one board (if you dont know that already). It uses what they call the Bridge to communicate between the 2. Basically it talks over the com port and you don't have to build your own protocol, it does it for you.
Now the Yun is turning out to be to low specked for what I want to do so now I want to use a Raspberry Pi and hookup an Arduino Mega to do all the low level sensor stuff.
As luck would have it Paul Stoffregen ported the library so it can work on any linux type system using any Arduino board
(Arduino Code) https://github.com/PaulStoffregen/Bridge
(Python Code for the linux side) https://github.com/PaulStoffregen/BridgeUSB
So what it does is you set-up the Pi so when you connect the Arduino it will auto login on the comm port as root (via the usb connection) and then it should start the Bridge.py script. Now here is my problem, in fact I have 2 of them
1) The Bridge.py script does not fire (it does not start up)
2) The Arduino does not auto connect on a Pi reboot.
I can see the Arduino is connecting as root when I plug it in
root#RedPi:~# who
root ttyACM0 2016-03-10 18:01
I have the Arduino side working as I can see it is sending the data.
If I cat the port I can see it is sending the data
cat /dev/ttyACM0
run-bridge
▒XX100▒q▒XX100▒q▒XX100▒q▒XX100▒q▒XX100▒q▒XX100▒q▒X ...........................
But it does not run or execute the "run-bridge" command. But if I type it as root on a ssh session it runs.
And then if I reboot the Pi I have to pull out the plug and push it back to connect to ttyACMo again. But when I do a lsusb I can see the Arduino there. I guess I have to add a bit of config to tell linux to do it at startup.
You have to add this bit. And I was hoping it would take care of the USB at boot as well
# UDEV Rules automatically start a shell on a USB Serial device.
#
# This file must be placed at:
#
# /etc/udev/rules.d/00-bridge.rules
#
KERNEL=="ttyACM*", RUN+="/usr/bin/run-bridge-udev", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{MTP_NO_PROBE}="1"
I hope you can help me. I do not want to rewrite all my code that is working on the Yun. So if I can port it it will be great.

Related

Accessing Raspberry Pi4 USB port with Python

I am using Raspberry Pi 4 which comes with 4 USB ports. For my project, I have two mics and both will be connected to Rsp via a USB port. I need to be able to choose which Mic needs to be ON. So basically I need to be able to switch/choose which USB port I want the sound to come in.
I need to be able to choose Mic1 or Mic2. I am writing my code in Python. Is there any library that gives me access to choose a specific UBS port? I really can't find anything.
Appreciate your help.
Regards

How to connect to USB TTY from BeagleBone Black?

I would like to establish serial communication from a Windows PC to the BeagleBone Black. The purpose is to have a Python application on the BeagleBone interact with a terminal running on the PC. I would like to use the same USB cable I use for the SSH connection (from PC to micro-usb on the BB), but instead of SSH, I want to open a serial connection via something like TeraTerm, and have a running python application connect to the TTY, something like /dev/ttyUSB. However, this TTY does not exist.
Note that I'm not trying to do serial debugging, as this article suggests. I'm also not trying to do this connection over UART. I specifically want to communicate with a python application via a terminal running on the PC. The Python application would use a library like pyserial.
Since the TTY is not showing on the BeagleBone, how can I proceed?
A TTL to USB converter will work. I got an older model that is still produced from some company. Here is one I found easily online at Adafruit: https://www.adafruit.com/product/954.
That will give you TX, RX, GND, and PWR. Please make sure to get a 3.3v type if you are using it for the BBB.
Here is some write up w/ questions/answers: https://askubuntu.com/questions/40959/how-do-i-connect-to-tty-com-dev-ttyusb0
Sometimes when you use PuTTY w/ Win 10 COM ports, it is necessary to make sure you get the COM port correct. Actually, every time! Click on the connection ICON on the bottom, right of the screen under the "^", click on the Open Devices and Printers, and then go to the BBB on the photo screen. Once you right click and go to Properties, finally click on the Hardware tab to find your COM Port. Then, one can use a COM Port on Win 10 w/ the BBB along w/ PuTTY.
So, w/ PuTTY, you can click the serial connection, type your COM Port (COM6 or whatever), and finally click Open.
...

How to program a atMega328p MCU with a Raspberry Pi 4 (Python)

I been looking everywhere online for this exact configuration but can't find much.
I want to program my AtMega328p MCU (its on a breadboard) using Python from my Raspberry Pi 4 but I am not sure how to check if communication is going on between them? I have the MISO, MOSI, SCLK, and CE0 pins from the Pi connected to the MISO, MOSI, SCK, SS pins on the AtMega328p respectively.
I understand I have to use SPI communication, however how can I exactly send data from the Raspberry Pi to the MCU to ensure there is communication between the two? Maybe some code to send to the MCU and receive it back? I been using the SPI Dev Python libraries but can't find much info on it. Thank you in advance!!
To load code onto the AVR (program it), you want to use existing software like avrdude that already speaks the AVR ISP protocol. avrdude already has support for using the RPi SPI headers - just use the linuxspi programmer type.
Here's an article by the author that explains it (although there are probably more recent articles if you search around) http://kevincuzner.com/2013/05/27/raspberry-pi-as-an-avr-programmer/
Is there a reason you want to do this from Python specifically? Or are you referring to communicating between the uC firmware and some Python code on the Pi?

WIFI Pineapple Nano and RPi GPIO

I just got a wifi pineapple nano, and have been a longtime raspberry pi enthusiast, so I'm super stoked to start joining the two. I've already got it connected to my Pi and have played around a bit with the setup. My specific curiosity right now is whether it's possible to write a program to perform GPIO tasks on the raspberry pi based on events occurring on a wireless LAN broadcast by the pineapple. An example would be to turn an LED on if a specific MAC address is detected, and said client is within some power threshold. My lack of knowledge at this stage is how the pineapple fits with the pi (or any other "host" for that matter).
Specifically, do I write my program (probably python, and later some html and JavaScript served over flask) and host it on the pi? If so, how does it interact with the pineapple to get the MAC address and connection power dB? If not, do I host it on the pineapple? If so, how does the program interact with the pi to utilize its GPIO pins? How would I compile my code so that the pineapple can use it? Are there modules already available that can get me most of the way to my goal?
I don know Pineapple Nano very much, but I found, there is an API with module Tracking.
API You should be able to set script which will run when client with specific MAC address connect to AP. In script you can call some method API/Flask on your Pi.
Next solution can be gpiozero library, which has module pingserver doc,
where you can checking some URL if is online. If you set on your AP static IP addresses for clients you want to track, you can use this module to determine, if is online (connected) or offline (disconnected)
example:
from gpiozero import PingServer, LED
from signal import pause
client= PingServer('192.168.0.155')
led = LED(4)
led.source_delay = 60 # check once per minute
led.source = client.values
pause()
In this example, when client with IP address 192.168.0.155 go online, LED will turn on.
Maybe it will help you.
Peace

Writing web app to program Arduino

I want to write a web app allowing people to program Arduino remotely. There will be a live video stream of the Arduino with lolShield.
What's the best way to flash the Arduino within Python?
inotool is a commandline wrapper for the sketch environment and is written in python.
Or you could use exec() to run one of the commandline solutions in Command line Arduino compiling and downloading?
avrdude is the tool to program an Arduino over a serial interface. So basically you need a serial interface from your web server to the Arduino in question. Here are two approaches that may help you get there (I had tried the first one about 1.5 years ago, it worked like a breeze):
Xbee RF modules can transparently be operated in serial mode, perfect for this use case. The downside of this is that you need a local in-between machine that is connected to the internet and acts as the gateway to the Xbee/Zigbee network. Programming an Arduino over Xbee has been described in detail at ladyada.net.
If you need direct WiFi connectivity this should work the same way. XBee comes in two parts: 1) the adapter, which connects to the Arduino over a serial interface, 2) the actual RF module. So if you can get a WiFi module that sits on top of a XBee adapter, the same approach should work. I haven't tried this myself, but I guess combining the first approach with the following from homebrew-tech.com should work.
Inotool is a good option. In addition to that you can also try the following two options as well.
Arduino 1.5.x only
If you are using Arduino 1.5.x then you can use the arduino executable can accept commandline parameters.
Note that Arduino 1.5.x is still in beta, so you may face some issues.
Arduino 1.0.x
If you are using Arduino 1.0.x then you can use my makefile for Arduino which can be used to compile and upload Arduino (or plain AVR C) programs to Arduino from the commandline.

Categories