I am working on a project where I need to detect objects from IP camera on PC using TensorFlow and the data of the detected object to raspberry pi and control its GPIO pins accordingly.
I am using python on both ends.
I read somewhere to form a client-server network between the two.
I need some ideas on how to approach this problem. Thank you. I hope my question was clear.
Extra Information: I am currently using Raspberry pi on PC via ethernet cable. Also, both raspberry pi and my PC are connected to the same Wifi router. I hope this information helps.
You can use sockets to make the Raspberry Pi and your PC communicate. You can use socket.accept(conn, address) to accept a connection and conn.recv(buffer) to receive data.
I'm a big fan of using Redis for this type of thing. It has a small footprint, is simple to set up and is lightning fast. It is a "networked data structure server". "Networked" means that its clients can be on the same machine or anywhere on the network. The data structures it serves include:
strings
integers
atomic integers
lists
queues
sets
sorted sets
hashes
There are bindings for Python, C, C++, PHP, Ruby and rather brilliantly, the shell. That means you can inject values into queues, lists or sets directly from any Terminal on your network whilst your app is running, in order to test it or monitor it.
Example here.
Related
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?
I've managed to write a Python program for my Raspberry Pi that interacts with BLE via D-Bus and can register GATT services and store data in chatacteristics that external devices can read. However, my goal is to send images from my Raspberry Pi (peripheral) to an Android/iOS device (central). I've started searching for information on how to do that and discovered that there is a pretty low limit on how much data can be stored in a GATT characteristic (answers range from 20 to 512 kB). Because of this limit, the larger data must be split into chunks and transferred using a rather complicated algorythm involving GATT notifcations. That made me wonder if I'm on the right path. It looks like an overhead to implement such a complicated algorythm to send an image via Bluetooth and the low data size limit makes me think that BLE isn't meant for this. Maybe I should just use classic Bluetooth with sockets? Or maybe someone can point me to an example of an application which sends image via BLE, because I couldn't find anything useful on the internet. I mainly chose to use BLE because I want to write the Android/iOS application using React Native and it only supports BLE client. Does iOS even support Bluetooth classic?
I may be confusing a few concepts here so any help is appreciated.
Q1: Is it possible to attach any sensor in the world to the USB on my computer as long as it gives me analog data, and read its output? (e.g. pH, temperature, oxygen sensor etc as long as it gives me analog data)
Q2: If so, then what is the simplest way in python for me read such data.
Comment: I am trying to bypass using PLC's, and trying to see if I can get the output from the sensor directly to the PC. (I do not have drivers for these sensors)
Actual Need: I have an oxygen sensor connected to my computer via a USB. The oxygen sensor is able to send out analog data. The obvious way is to go through a PLC. However, I would like a solution which by-passes PLC's so I can connect the sensor directly to my PC via USB.
The USB port on your computer cannot read analog data because USBs work with digital signals. You would need an analog-to-digital converter (ADC).
as #digitaLink answered, it is not possible directly via USB and yes, the obvious way is to use a PLC.
I would go the PLC way - in fact, I did it a few times in the past - and start with an Arduino and later develop a custom PCB, put it in a box and done.
Another possibility is to use a raspberry pi (or similar SBC), which has the GPIOs you can use for analog read.
Edit: there is another possibility.
The sensor you use now is _very_likely_ a PLC in itself, that is, the sensor is attached to a microcontroller that uses the USB port for serial communication. Now, the drivers you are missing do nothing else but decode the data coming through the serial port. Take a look inside your harware and try to find out what components there are in.
So what you could do is to try to find out how to communicate with the sensor via a serial terminal. It is probably possible to monitor serial communication (although I must admit, I don't know how to do that), reverse engineer the code and write your own driver in python. You could learn a lot from this, even if you don't succeed.
I am trying to send some data between 2 raspberry pi's over wifi without them being connected to a network.
I want it to work similar to the way beacons and probe requests work, where a broadcast can be sent out the wireless interface.
the data I want to send will be the hostname of the device and the time the packet was sent.
I've been trying to figure this out for the last few days but I cannot get anything to work without them being on the same network.
Is anybody able to point me in the right direction?
I'm not too fussed about what language I use. I have been trying python and C with little success.
Note: This is not really an answer, just some ideas to research, so feel free to edit or comment with corrections.
There are 6 modes a wifi adapter can operate in. From wikipedia:
Master (acting as an access point), Managed (client, also known as station), Ad hoc, Mesh, Repeater, and Monitor mode.
But I believe not all wifi adapters support all modes, so make sure you have suitable hardware.
I would suggest adhoc or mesh would be the most suitable to your purpose. With adhoc mode at least the devices would need to be configured beforehand to use the same SSID and channel. This may not apply to mesh mode.
A quick search yields a few links in regards to using Raspberry Pis in a mesh network:
http://hackaday.com/2012/11/14/mesh-networking-with-multiple-raspberry-pi-boards/
Wireless mesh networking on Raspberry Pi using batman-adv protocol
http://www.netlore.co.uk/airmesh/?page=about
I would also look at using the Dot11* family of packets in the excellent Python Scapy library (not to be confused with Scrapy). You should be able to craft custom packets and transmit them if the interface is in the right mode. Here's a project that creates fake access points that probably contains good info: https://github.com/rpp0/scapy-fakeap
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.