Hi guys
I have been searching all over for a solution to this problem and have come up short. I am using a HC-05 Bluetooth to send incoming data from a LSM9DI IMU connected to an Arduino Uno to my computer. I'm receiving the data in a python script and then storing it into a text file. The Arduino code is:
#include <Wire.h>
#include <SPI.h>
#include <SparkFunLSM9DS1.h>
LSM9DS1 imu;
#define PRINT_CALCULATED
#define PRINT_SPEED 250
static unsigned long lastPrint = 0; // Keep track of print time
#define DECLINATION -8.58 // Declination (degrees) in Boulder, CO.
void setup()
{
Serial.begin(115200);
Wire.begin();
if (imu.begin() == false) // with no arguments, this uses default addresses (AG:0x6B, M:0x1E) and i2c port (Wire).
{
Serial.println("Failed to communicate with LSM9DS1.");
Serial.println("Double-check wiring.");
Serial.println("Default settings in this sketch will " \
"work for an out of the box LSM9DS1 " \
"Breakout, but may need to be modified " \
"if the board jumpers are.");
while (1);
}
}
void loop()
{
// Update the sensor values whenever new data is available
if ( imu.gyroAvailable() )
{
imu.readGyro();
}
if ( imu.accelAvailable() )
{
imu.readAccel();
}
if ( imu.magAvailable() )
{
imu.readMag();
}
Serial.print(imu.calcGyro(imu.gx), 2);
Serial.print(", ");
Serial.print(imu.calcGyro(imu.gy), 2);
Serial.print(", ");
Serial.print(imu.calcGyro(imu.gz), 2);
Serial.print(" ");
Serial.println(" deg/s");
Serial.print(imu.calcAccel(imu.ax), 2);
Serial.print(", ");
Serial.print(imu.calcAccel(imu.ay), 2);
Serial.print(", ");
Serial.print(imu.calcAccel(imu.az), 2);
Serial.print(" ");
Serial.println(" g");
Serial.print(imu.calcMag(imu.mx), 2);
Serial.print(", ");
Serial.print(imu.calcMag(imu.my), 2);
Serial.print(", ");
Serial.print(imu.calcMag(imu.mz), 2);
Serial.println(" gauss");
}
and the reciveing python code is
import serial
serialPort = serial.Serial(port='COM20', baudrate=115200, timeout=0, parity=serial.PARITY_EVEN, stopbits=1)
size = 1024
while 1:
data = serialPort.readline()
if data:
data = data.decode("utf-8")
print(data)
file1 = open(r"C:\Users\bbb\Downloads\imu_2.txt","a")
file1.write(data)
file1.close()
Every time I try to run this setup I'm thrown an error that reads:
UnicodeEncodeError: 'charmap' codec can't encode character '\u0722' in position 37: character maps to
I've used the HC 05 for projects before with this python code and everything has been fine. I'm also able to see the correct output from the LSM9DS1 on the Serial monitor. I'm also able to receive and decode incoming bytes from other sensors connecting to the analog ports. I'm not sure if its because this is an IC2 communication or that I'm using a library in the Arduino code or what. I've tried a lot of different things to get this to work like changing the baudrate, changing the .decode method, changing the output from the Arduino but I can't get anything to work. I've also looked around on the web but can't seem to find exactly what I need to help me either. Any help at all would be greatly appreciated. Thanks so much!