I am attempting to pass motion data (accelerometer, gyroscope,...) from an IMU to my computer over a Bluetooth Low Energy (BLE) connection. I purchased the FXOS8700 + FXAS21002 to generate motion data and am using a wired I2C connection to pass that data to my BLE board, an nRF52840. The I2C connection works and I can get data off the nRF52840 via a wired connection. I have also managed to establish a Bluetooth connection between my BLE board and my computer and can view the BLE characteristics, but I can't figure out how to program the nRF52840 to write my motion data into these characteristics to pass them over Bluetooth.
Below is the code I have used to establish an I2C connection and create the BLE connection. Missing is the code to create BLE characteristics.
# Import ble libraries
import _bleio
import adafruit_ble
from adafruit_ble.advertising.standard import Advertisement
from adafruit_ble.services.standard.device_info import DeviceInfoService
# Import libraries for the FXOS8700 accelerometer and magnetometer
import time
import board
import busio
import adafruit_fxos8700
# CircuitPython <6 uses its own ConnectionError type. So, is it if available. Otherwise,
# the built in ConnectionError is used.
connection_error = ConnectionError
if hasattr(_bleio, "ConnectionError"):
connection_error = _bleio.ConnectionError
# PyLint can't find BLERadio for some reason so special case it here
ble = adafruit_ble.BLERadio() # pylint: disable=no-member
# Initialize I2C bus and device
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_fxos8700.FXOS8700(i2c)
isConnected = 0
while not isConnected:
print("Scanning...")
for adv in ble.start_scan(Advertisement, timeout=5):
name = adv.complete_name
if not name:
continue
isConnected = 1
print("Connected")
break
# Stop scanning whether or not we are connected
ble.stop_scan()
print("Stopped scan")
while True:
# Read acceleration and magnetometer
accel_x, accel_y, accel_z = sensor.accelerometer
mag_x, mag_y, mag_z = sensor.magnetometer
# Write acceleration and magnetometer data to BLE characteristics...
How do I write data into a BLE characteristic and send that data over Bluetooth? Do I need to create a new BLE characteristic or service? I feel that I am missing something fundamental here...
Additional information:
I am using the ble() function in MATLAB to connect to the nRF52840 and read the BLE characteristic data. I was initially trying to pass every single measurement over Bluetooth (likely requiring a more complex program with data buffers), but at this point I would be happy simply being able to read the most recent measurement.
Since the BLE board I'm using is so popular, I expected to find numerous examples of data transfer over Bluetooth, but I haven't found any examples of sending data with BLE. There are numerous examples using a BLE-UART connection (not visible to MATLAB) or sending data to the BLE board, but none sending data from the BLE board, except via this UART method (but I can't find a way to access that data).
Related
As the title indicates, I need to create a bridge betweeen pd and arduino UNO but I can't get it to work.
I need to start an arduino process after receiving a message from my computer through puredata, using the comport object.
Since comport object in pd doesn't allow me to connect to the port used by arduino (listed trough "devices" message in pd) I don't understand how to stablish a communication between them.
[comport]: could not open device COM3:
failure(5) ERROR_ACCESS_DENIED
Arduino is connected to the computer by usb cable.
If been able to sort it out using in arduino.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1);
And then referring to the serial with the variable used, mySerial, in this case.
Since this moment, when I was trying to do it using a basic included Serial communication, without library, I was not able to find the needed port free in puredata. Now it seems to work well, I cannot figure it out why not before.
At a high-level, I am trying to convert serial data coming off of an RS-232 cable so that an I2C device can read it. I am not married to any one component or solution but the transmitting device, a voltage controller, will only send via serial, and the receiving device I want to use only supports I2C.
More specifically:
I am using this PC meterbus adapter to get data off of a voltage controller, and the output format it supports is RS-232. I have an IoT device that uses a Feather S2 board as its control unit, and I basically want to send the data coming off of the voltage controller to the cloud using that device. It only supports I2C via a little header that the feather S2 plugs directly into.
So, to recap, we have an RS-232 cable plugging into this Mikroe device. The device connects to a Feather S2 board using the SDA and SCL pins. The problem I'm having now is that when I run a sketch to detect connected I2c devices:
import time
import board
i2c = board.I2C()
while not i2c.try_lock():
pass
try:
while True:
print(
"I2C addresses found:",
[hex(device_address) for device_address in i2c.scan()],
)
time.sleep(2)
finally:
i2c.unlock()
It's returning:
I2C addresses found: []
I can't get any useable data from my voltage controller if I can't even get the board to detect the serial to I2C converter.
I've ruled out bad soldering, no pullups, etc. I'm thinking maybe this device isn't appropriate for this use-case and I need something else, or, having read the datasheet, maybe I need to send some sort of start condition from the feather to the I2C click to get it to start transmitting.
If that's the case, I'm at a loss, because I've never interfaced with an I2C device NOT using a circuitpython library for that device. I tried looking at Mikroe documentation, but it seems like that community doesn't support Python. Does anyone have any suggestions about where to begin? Either a different module to use for my serial-to-I2C conversion, or some python approach to coax the Mikeroe module into playing nice with my Feather S2.
Thank you for reading my question! I appreciate any and all help!
I have a project in hand where I need to connect 5 or more arduinos as slaves to Raspberry Pi. Load Cells, Reed Switch, Solenoid lock will be connected to each of the arduino. The arduinos need to send the weight readings when a communication is started by the raspberry pi(master). Only a single arduino will be activated at a time. The arduinos will be placed at a maximum of 6ft distance from the raspberry pi. I need advice regarding how to make this connection. I read that I2C cannot be used for long distances so I am unsure if 6 ft is a long distance for I2C. Next, I am trying to see if a USB would work for my case but the issue is the Pi has only 4 USB slots. So can I use a external USB hub with an external power supply and connected each of the arduinos to the USB hub and provide individual power supply to the arduinos? Will this arrangement work or should I be looking at any other protocol apart from I2C and USB?? Any advice on this will be much appreciated. Thanks a lot for your time.
Arduino (Nano, Uno, Mega etc.) can communicate via SPI, I2C or UART.
Long story short, SPI is not suitable for your application. It is used for fast data transfer over short distances (usually milimeters or centimeters), so mainly for communication between chips mounted on the same PCB or PCBs close together (e.g. display shields).
Using I2C is perfectly fine (let's say up to 10 meters) and in your case it is a way to go. The maximum possible length depends on baud rate, for 10 meters a 9600 baud rate would be OK. The big advantage is that you need only 2 wires to connect all Arduinos, the disadvantage is that only one device can transfer data at the time – in your case, that does not matter.
UART is used for communication with many external modules (GSM, GPS, HMI, ...) and also in combination with USB-TTL chip for communication via USB (virtual COM port). In your case, you can use UART e.g. in combination with external UART-RS485 converter module, but there is no need since you can use I2C.
We are looking at using the Telit BlueMod+SR chip in a hardware idea we are working on. Towards that I've been trying to build a Bluetooth Low Energy (BLE) server simulation using the Telit BlueEva+SR evaluation board driven over USB by a Python script.
The two relevant manuals appear to be:
BlueMod+SR AT Command Reference
Terminal I/O Profile Client Implementation Guide (though I'm implementing the server)
(N.B. these are available here but are behind a register/login.)
I'm stuck on something basic: how to send or receive data. I understand that this is done by setting the value of a Generic Attribute Profile (GATT) service's characteristic. The BlueMod+SR already has the GATT service characteristics that I need (a UART data TX characteristic and a UART data RX characteristic) on its Terminal I/O Service. The UUID's of the characteristics I need are given in the Terminal I/O Profile Client Implementation Guide but I cannot see how to read from nor write to them. The AT Command Reference has a section on GATT Server commands but the only one listed, +LEATTRIB, is for defining the attributes for a service (and the ones I need are already defined).
What are the commands I need to read and write the values for the characteristics UART Data TX, UART Data RX, UART Credits TX, and UART Credits RX?
It turns out that I did not need to use the credit mechanism, that's handled for me. So to write to the TX characteristic I can either connect to BLE and just write the data, or use the multiplexing and write the data to channel 0x01 (Terminal I/O). Reading the RX characteristic si similarly just reading the serial connection.
What is a way to read some data from the USB device TelosB Mote?
It sends packets of 12 octest, and all I want to do is to read two of them. I want to be able to set the transfer speed and the data buffer - I guess.
This board has an integrated USB device port. I've read about the USB shield 2 library, but I've seen it helps connecting it with an Android phone.
How can I fix this problem?