I want to configure I2C for raspberry pi using PYTHON or last choice C. I have worked on ATMEL micro controller, it provide I2C communication with any device. I want some similar mechanism for raspberry pi. I have following questions:
1. We have to define address of every device in I2C bus. If i want to send some data from ATMEL micro controller to raspberry pi (write data to raspberry pi), what will be the address of raspberry pi or how we can set the address.
2. Is there any interrupt or something like that if we receive some data on I2C bus?
3. Which library will be best for PYTHON or C?
4. Can i write my custom codes for implementing I2C protocol?
Please help.... Thanks in advance..
I suggest you use i2c-dev and i2c-bcm2708 module, where you will have the i2c buses exposed to the /dev filesystem.
$ sudo modprobe i2c-dev
$ sudo modprobe i2c-bcm2708
Now will will have i2c buses exported, list them with
$ ls /dev/i2c-*
Using it is not that simple because it is i2c, it has different protocols and addresses.
If you are going to use it in C, this is the tutorial.
In python, you can install the i2cdev package and use it as this:
from devi2c import I2C
device, bus = 0x42, 0
i2c = I2C(device, bus)
value = i2c.read(1) # read 1 byte
i2c.write(b’some raw data’) # write bytes
i2c.close() # close connection
Related
I'm working on an object detection project for IoT using a webcam and servo. In short, when the object detected by the webcam matches the data in the system, the servo will move. Can the webcam be connected to the laptop, and the servo on the Raspberry Pi? So the input is from the laptop and the output is on the Raspberry Pi using pi-gpio (Remote GPIO). How to? Thanks.
This link shows the GPIO Zero library being used with pigpio to allow remote control of the GPIO pins, from either another raspberry pi - or a PC. Once you configure GPIO Zero to use the pigpio library and connect, I believe you can just use the GPIO Zero libraries as per normal to control the Servo. (though I have not tried this myself!)
However I would probably use MQTT to decouple the two systems. If you run an MQTT broker on the Raspberry Pi (eg. Mosquitto) then the webcam software can publish a message to the MQTT broker, and the raspberry pi software can subscribe and act accordingly.
You can also run this with a cloud based MQTT system (eg. HiveMQ) so the Raspberry Pi and the PC with the Webcam don't even have to be in the same location.
A quick way is to use the Python socket library. Both devices need to be connected to the same network, and the sender needs to know the IP address of the receiver.
I have a Raspberry Pi connected to an Arduino Mini that it normally communicates with over I2C. But I'd also like to be able to reflash the Mini with new code using Arduino-Cli from the Raspberry Pi (kinda rhymes!). This would involve connecting the Raspberry Pi's GPIO serial port to the Arduino's serial port. Additionally, the Arduino Mini requires a manual reset to be applied before its code can be reflashed, which is something the Raspberry Pi can do by toggling a GPIO pin attached to the Mini's reset line. I can do this with a simple Python script. The question is: is there a way for Arduino-Cli to call additional scripts as part of the upload command?
I would use remotely a I2C expansion (IO PCF8574) connected to a RPI 192.168.0.10 from a different RPI 192.168.0.11 like the remote GPIO.
I followed the instructions from http://abyz.me.uk/rpi/pigpio/index.html but I'm a newbie and I can't see anything related to "networked" i2c but only local.
I'm Using Python3 on Raspberry Buster
Can someone help me with this solution or proposing different ones?
Thanks in advance for any help
Abartolo
I'm pretty new to Bluetooth so this might be trivial, but I'll still ask:
I would like to connect 2 devices via Bluetooth - a mobile device with a Linux device (like Raspberry Pi, but another one...).
Side 1 - the mobile: It has an app that should pair with the Linux device, and send some data to it (a msg with "Hello" in this point).
Side 2 - the linux device: It should have a kind of listener to the fact that a device was connected to it via bluetooth, and then expect the data, receive it, and process it.
Side 1 is all fine and clear to me.
As for side 2, for now I only use some command line commands to turn Bluetooth on, set some name to the device, and wait for scan. I do it with "hciconfig", by running the following commands in Python script, one after the other:
hciconfig hci0 up
hciconfig hci0 name MyDevice
hciconfig hci0 sspmode 1
hciconfig hci0 piscan
At this point, my device is discover-able to my mobile and it pairs with it successfully. Now, I'm stuck with the listening part. I would like the linux device to run a certain function (prefer in Python) when the device is paired, and expect to receive data from it. I've read some links over the net, using RFCOMM and Bluez, but none succeeded...
Can someone please assist?
Thanks
Good morning, there is a library written in Python that handle Bluetooth connection for you already PyBluez
to install use sudo pip install pybluez
here is an example on how to use sockets to communicate with bluetooth devices
import bluetooth
bd_addr = "01:23:45:67:89:AB"
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
sock.send("hello!!")
sock.close()
the complete guide is at Bluetooth Programming with PyBluez
`
im working on a project to connect a Pic to a Raspberry pi via uart.
I know they both have uart pins, but I need to connect them via usb, the cable also serves as the power supply for the Pic.
So my question is, is it possible to use python, C# might also be an option with mono, to use an USB port on the Raspberry Pi for UART?
this is a tutorial I found about uart on the Raspberry Pi with Python
a turorial on what is uart
Not possible.
USB uses two 'pins' for transmission using 'differential signaling'.
This means, both pins are used for sending and transmission.
In UART you use one pin for transmission and one for reception.
Without any interface, not possible.