Hi,
I’m new to coding with processing, so apologies in advance for rookie mistakes. I’m working on a project where I’m collectiog multiple orientation angles from 2 BNO055 sensors using Arduino. The idea is to create an interface using Processing, where if I press the ‘DATA’ button, the angle values get stored as a .csv file to be used later (I’ve attached a pic). I will be very grateful if you could! Please help me…
Here is my Arduino code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <Volume.h>
// The two BNO055 modules, bnoB has the ADR pin wired to 3.3v to change its i2c address
// Both are wired: SCL to analog 5, SDA to analog 4, VIN to 5v, GRN to ground
Adafruit_BNO055 bnoA = Adafruit_BNO055(-1, BNO055_ADDRESS_A);
Adafruit_BNO055 bnoB = Adafruit_BNO055(-1, BNO055_ADDRESS_B);
int xA; int yA; int zA; //First Measure Forearm
int xA_f; int yA_f; int zA_f; //Fol0ing Measures
int xB; int yB; int zB; //First Measure Upper Arm
int xB_f;int yB_f;int zB_f; //Following Measures
int vibpin = 9; //Pin Number for Vibrating Motor
int buzzpin = 7; //Pin Number for Buzzer
void setup() {
Serial.begin(9600); //Begin the serial trasmission
Serial.setTimeout(500); // The program waits 50ms after which input won't be taken
//Serial.println("Orientation Sensor Test"); Serial.println("");
pinMode(9, OUTPUT);
pinMode(7, OUTPUT);
//Check that both the sensors are correctly mounted
if(!bnoA.begin()) {
Serial.print("Ooops, BNO055(A) not detected");
while(1);
}
bnoA.setExtCrystalUse(true);
if(!bnoB.begin()) {
Serial.print("Ooops, BNO055(B) not detected");
while(1);
}
bnoB.setExtCrystalUse(true);
Serial.println("Be Ready for First Measure in 1 secs"); Serial.println("");
delay(1000);
//Take the first orientation angles that we will later compare with the fol0ing ones
Serial.println("First Measure: "); Serial.println("");
imu::Vector<3>
euler = bnoA.getVector(Adafruit_BNO055::VECTOR_EULER);
//Serial.print("X1: ");
xA = euler.x();
Serial.print(xA);
Serial.print('\t');
yA = euler.y();
Serial.print(yA);
Serial.print('\t');
zA = euler.z();
Serial.print(zA);
//Serial.println("");
//Serial.println("");
euler = bnoB.getVector(Adafruit_BNO055::VECTOR_EULER);
//Serial.print("X2: ");
xB = euler.x();
Serial.print(xB);
Serial.print('\t');
yB = euler.y();
Serial.print(yB);
Serial.print('\t');
zB = euler.z();
Serial.println(zB);
//Serial.println("");
//Serial.println("");
//Serial.println("");
//Serial.println("");
delay(250);
Serial.println("Following measurements: "); Serial.println("");
delay(250);
}
void loop() {
//Take the following angles and name that in a different way with respect to the first ones
delay(1000);
imu::Vector<3>
euler = bnoA.getVector(Adafruit_BNO055::VECTOR_EULER);
//Serial.print("X1: ");
xA_f = euler.x();
Serial.print(xA_f);
Serial.print('\t');
yA_f = euler.y();
Serial.print(yA_f);
//Serial.print('\t');
zA_f = euler.z();
Serial.print(zA_f);
// Serial.println("");
//Serial.println("");
euler = bnoB.getVector(Adafruit_BNO055::VECTOR_EULER);
Serial.print('\t');
int xB_f = euler.x();
Serial.print(xB_f);
Serial.print('\t');
int yB_f = euler.y();
Serial.print(yB_f);
Serial.print('\t');
int zB_f = euler.z();
Serial.println(zB_f);
//Serial.println("");
//Serial.println("");
//bnoA.enterLowPowerMode(); //Low Power Mode
// CONDIZIONI PER ACCELEROMETRO A (20 0x29 Forearm)
if (Serial.available()){
char val = Serial.read();
///////////////////////////////////////////////////////////////////////////////////////////////////////////a
if (val == 'a'){//The x goes from 0 to 360, the initialization point is always 0
noTone(7);
if (xA_f < 350 && xA_f > 50) //changed to 20 deg from initial 10 deg
{ if (val == 'h')
{analogWrite(9,153); delay(200);}
analogWrite(9,153); }
else
{
analogWrite(9,0);}
Serial.println("");
//The y makes 90 ° shots
if ((yA_f < (yA - 15 )) || (yA_f > (yA + 15)))
{
analogWrite(9, 153);}
else
{
analogWrite(9, 0);}
Serial.println("");
//The z snaps at 180 °
if ((zA_f < (zA - 15 )) || (zA_f > (zA + 15)))
{
analogWrite(9, 153); }
else
{
analogWrite(9, 0);}
Serial.println("");
Serial.println("");
// CONDIZIONI PER ACCELEROMETRO B (0 0x28 Arm)
//The x goes from 0 to 360, the initialization point is always 0
if (xB_f < 350 && xB_f > 50)
{
analogWrite(9, 153); }
//flag_xb = 1;}
else
{
analogWrite(9, 0);}
Serial.println("");
//La y fa scatti di 90°
if (((yB_f < (yB - 15 )) || (yB_f > (yB + 15)))
){
analogWrite(9, 153);}
else
{
analogWrite(9, 0);
}
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
delay(500);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////b
if (val == 'b'){//The x goes from 0 to 360, the initialization point is always 0
noTone(7);
if (xA_f < 350 && xA_f > 50) //changed to 20 deg from initial 10 deg
{
analogWrite(9,115); }
else
{
analogWrite(9,0);}
Serial.println("");
//The y makes 90 ° shots
if ((yA_f < (yA - 15 )) || (yA_f > (yA + 15)))
{
analogWrite(9, 115);}
else
{
analogWrite(9, 0);}
Serial.println("");
//The z snaps at 180 °
if ((zA_f < (zA - 15 )) || (zA_f > (zA + 15)))
{
analogWrite(9, 115); }
//flag_za = 1;}
else
{
analogWrite(9, 0);}
Serial.println("");
Serial.println("");
// CONDIZIONI PER ACCELEROMETRO B (0 0x28 Arm)
//The x goes from 0 to 360, the initialization point is always 0
if (xB_f < 350 && xB_f > 50)
{
analogWrite(9, 115); }
//flag_xb = 1;}
else
{
analogWrite(9, 0);}
Serial.println("");
//La y fa scatti di 90°
if (((yB_f < (yB - 15 )) || (yB_f > (yB + 15)))
){
analogWrite(9, 115);}
else
{
analogWrite(9, 0);
}
Serial.println("");
Serial.println("");
Serial.println("");
Serial.println("");
delay(500);
}
if (val == 'j') //For the DATA button
{
Serial.print(xA_f);
Serial.print(yA_f);
Serial.print(zA_f);
Serial.print(',');
Serial.print(xB);
Serial.print(yB);
Serial.println(zB);
} } }