Hi,
Kindly excuse my newbieness.
I am using ESP8266 Huzzah with LSM9DS0 to send data to my laptop for processing sound in Supercollider using OSC protocol.
It works, ...thanks to much help.
Unfortunatly, my friend is away and I have exhausted my own searching.
He gave me a sketch which should enable me to connect the boards to any wifi network and run everything together.
I am aware that in the sketch I need to enter: the ssid, password and IP address of my computer on the network.
However, when I upload the sketch using a different wifi network, I receive this message:
[i]Users/petervukmirovicstevens/Documents/Arduino/huzzah_to_sc/huzzah_to_sc.ino:4:57: fatal error: OSCMessage.h: No such file or directory
#include <OSCMessage.h> /// https://github.com/CNMAT/OSC
^
compilation terminated.
exit status 1
Error compiling for board Adafruit Feather HUZZAH ESP8266.[/i]
However, when I upload a simple sketch, Blink for example on the different network, it uploads just fine.
This leads me to believe there is something in this sketch that needs changing.
I have attached the .ino sketch, but in the event that is not helpful, below is the pasted code.
I very much appreciate the assistance.
Peter
//[code language="cpp"]
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <OSCMessage.h> /// https://github.com/CNMAT/OSC
#include <OSCBundle.h> /// https://github.com/CNMAT/OSC
#include <SPI.h> // Included for SFE_LSM9DS0 library
#include <Wire.h>
#include <SFE_LSM9DS0.h> /// https://github.com/sparkfun/SparkFun_LSM9DS0_Arduino_Library/tree/V_1.0.1
#define SET_OFFSET 12
///////////////////////
// LSM9DS0 I2C Setup //
///////////////////////
// Comment out this section if you’re using SPI
// SDO_XM and SDO_G are both grounded, so our addresses are:
#define LSM9DS0_XM 0x1D // Would be 0x1E if SDO_XM is LOW
#define LSM9DS0_G 0x6B // Would be 0x6A if SDO_G is LOW
// Create an instance of the LSM9DS0 library called `dof` the
// parameters for this constructor are:
// [SPI or I2C Mode declaration],[gyro I2C address],[xm I2C add.]
LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM);
long sendCount = 0;
long frameCount = 0;
//const char* ssid = "BTHub3-PQ5N";
//const char* password = "78cbae358d";
//change wifi network name and password below
const char* ssid = "jv";
const char* password = "15072000";
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
//const IPAddress outIp(192, 168, 1, 95);
//const IPAddress outIp(192, 168, 5, 111);
//Change ip address below (my MAC ip adrress on that network)
const IPAddress outIp(192, 168, 1, 2);
//const unsigned int outPort = 10101;
const unsigned int outPort = 57120;
float aX = 0.0f;
float aY = 0.0f;
float aZ = 0.0f;
float gX = 0.0f;
float gY = 0.0f;
float gZ = 0.0f;
float mX = 0.0f;
float mY = 0.0f;
float mZ = 0.0f;
void sendBundleViaOSC();
void getMag();
void getGyro();
void getAccel();
void setup() {
Serial.begin(115200);
pinMode(0, OUTPUT);
digitalWrite(0, HIGH);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
Wire.begin(4, 5); //set i2c SDA and SCL pins
// Use the begin() function to initialize the LSM9DS0 library.
// You can either call it with no parameters (the easy way):
uint16_t status = dof.begin();
// Or call it with declarations for sensor scales and data rates:
//uint16_t status = dof.begin(dof.G_SCALE_2000DPS,
// dof.A_SCALE_6G, dof.M_SCALE_2GS);
// Set output data rates
// Accelerometer output data rate (ODR) can be: A_ODR_3125 (3.225 Hz), A_ODR_625 (6.25 Hz), A_ODR_125 (12.5 Hz), A_ODR_25, A_ODR_50,
// A_ODR_100, A_ODR_200, A_ODR_400, A_ODR_800, A_ODR_1600 (1600 Hz)
dof.setAccelODR(dof.A_ODR_100); // Set accelerometer update rate at 100 Hz
// Accelerometer anti-aliasing filter rate can be 50, 194, 362, or 763 Hz
// Anti-aliasing acts like a low-pass filter allowing oversampling of accelerometer and rejection of high-frequency spurious noise.
// Strategy here is to effectively oversample accelerometer at 100 Hz and use a 50 Hz anti-aliasing (low-pass) filter frequency
// to get a smooth ~150 Hz filter update rate
dof.setAccelABW(dof.A_ABW_50); // Choose lowest filter setting for low noise
// Gyro output data rates can be: 95 Hz (bandwidth 12.5 or 25 Hz), 190 Hz (bandwidth 12.5, 25, 50, or 70 Hz)
// 380 Hz (bandwidth 20, 25, 50, 100 Hz), or 760 Hz (bandwidth 30, 35, 50, 100 Hz)
dof.setGyroODR(dof.G_ODR_95_BW_125); // Set gyro update rate to 190 Hz with the smallest bandwidth for low noise
// Magnetometer output data rate can be: 3.125 (ODR_3125), 6.25 (ODR_625), 12.5 (ODR_125), 25, 50, or 100 Hz
dof.setMagODR(dof.M_ODR_100); // Set magnetometer to update every 80 ms
// begin() returns a 16-bit value which includes both the gyro
// and accelerometers WHO_AM_I response. You can check this to
// make sure communication was successful.
Serial.print("LSM9DS0 WHO_AM_I’s returned: 0x");
Serial.println(status, HEX);
Serial.println("Should be 0x49D4");
Serial.println();
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(0, LOW);
delay(10);
digitalWrite(0, HIGH);
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
sendCount ++;
frameCount++;
if (frameCount < 2) {
digitalWrite(2, LOW); //blue LED on
} else {
digitalWrite(2, HIGH);
}
if (frameCount > 500) {
frameCount = 0;
}
if (sendCount > 1000)
{
getGyro(); // Print "G: gx, gy, gz"
getAccel(); // Print "A: ax, ay, az"
getMag(); // Print "M: mx, my, mz"
//GC: commented this out
//sendBundleViaOSC();
//GC: added this below
sendViaOSC();
delay (5);
}
}
void sendViaOSC() {
OSCMessage msg("/esp/magX");
msg.add(aX);
//msg.add("/esp/magY");
msg.add(aY);
//msg.add("/esp/magZ");
msg.add(aZ);
Udp.beginPacket(outIp, outPort);
msg.send(Udp);
Udp.endPacket();
msg.empty();
sendCount = 0;
}
void sendBundleViaOSC() {
OSCBundle bndl;
bndl.add("/esp/magX").add(mX);
bndl.add("/esp/magY").add(mY);
bndl.add("/esp/magZ").add(mZ);
bndl.add("/esp/accelX").add(aX);
bndl.add("/esp/accelY").add(aY);
bndl.add("/esp/accelZ").add(aZ);
bndl.add("/esp/gyroX").add(gX);
bndl.add("/esp/gyroY").add(gY);
bndl.add("/esp/gyroZ").add(gZ);
Udp.beginPacket(outIp, outPort);
bndl.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
bndl.empty(); // empty the bundle to free room for a new one
// Serial.println(mX);
}
void getMag()
{
// To read from the magnetometer, you must first call the
// readMag() function. When this exits, it’ll update the
// mx, my, and mz variables with the most current data.
dof.readMag();
// Now we can use the mx, my, and mz variables as we please.
// Either print them as raw ADC values, or calculated in Gauss.
mX = dof.calcMag(dof.mx);
mY = dof.calcMag(dof.my);
mZ = dof.calcMag(dof.mz);
}
void getGyro()
{
// To read from the gyroscope, you must first call the
// readGyro() function. When this exits, it’ll update the
// gx, gy, and gz variables with the most current data.
dof.readGyro();
gX = dof.calcGyro(dof.gx);
gY = dof.calcGyro(dof.gy);
gZ = dof.calcGyro(dof.gz);
}
void getAccel()
{
// To read from the accelerometer, you must first call the
// readAccel() function. When this exits, it’ll update the
// ax, ay, and az variables with the most current data.
dof.readAccel();
// If you want to print calculated values, you can use the
// calcAccel helper function to convert a raw ADC value to
// g’s. Give the function the value that you want to convert.
aX = dof.calcAccel(dof.ax);
aY = dof.calcAccel(dof.ay);
aZ = dof.calcAccel(dof.az);
}
//
huzzah_to_sc.ino (6.55 KB)