Hi guys I am still having issues and am hoping you can help. I rewired my breadboard, with a common ground going to the arduino. First question, is this ground correct? Here is an updated picture of my set up:
Second question, and hopefully this isn’t a double edged sword. Sometimes my electron will boot up, breathe cyan, and then turn solid cyan. I’ve read this is due to errors, but I’m not sure why this is happening?
Third set of questions. I am noticing my electron status change sometimes when I power on my arduino. This is fairly odd since I can’t reliably replicate this. On a couple of occasions, I noticed my arduino code is also getting hung up on Wire.requestFrom(0x8, 16); I’ve tried changing the decimal address to hex, different number of bytes requested, as well as including and excluding the optional arguments. Any help would be greatly appreciated! My arduino hangs after printing out “Br”.
Updated Arduino Master Code:
#include <Console.h> // to communicate over wifi
#include <Bridge.h>
#include <Process.h> //for gettime function
#include <Wire.h>
//int rxpin = 0;
float data =1.321;
String val_1str = "";
/*
On the Photon, Electron, P1 and Core, the I2C interface (Wire) is on D0 and D1:
DO: SDA
D1: SCL
*/
byte incomingb =100;
byte incomingc =200;
void setup() {
// Initialize the Bridge and the Serial
//Bridge.begin();
//Console.begin();
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
Serial.println("setup complete.*>>");
}
void loop() {
// variables
// incomingb= digitalRead(A4);
// Serial.println(incomingb);
// incomingc = analogRead(A4);
// Serial.println(incomingc);
int packet_size = 4; //sizeof(float);
Serial.print("packetsz is "); //mtp feedback
Serial.println(packet_size); // mtp feedback
// send READ request to slave
Serial.println("Br");
delay(1);
Wire.requestFrom(0x8, 16); // request 6 bytes from slave device #8 , third arg is true
//Wire.requestFrom(8, packet_size); // request 6 bytes from slave device #8Serial.println("ARRRRR");
Serial.println("AFTERRRR");
int i = 0;
char msg[32];
float val_1 = 0.0;
float val_2 = 0.0;
//char* status_msg = NULL;
// JOSH: Added this in b/c maybe it's not getting all the data we need.
unsigned long t_request = millis();
// while (i < packet_size) {
// Serial.print(i);
// // timeout will be performed if slave takes too long to transmit data
// if ((millis() - t_request) > 1000) {
// Serial.println("TIMEOUT OCCURED!!!");
// break;
// }
// collect all data from slave (note: this may fail if master reads faster than slave writes)
while (Wire.available()) { // slave may send less than requested
msg[i] = Wire.read(); // read msg packet byte by byte
Serial.println(msg[i]); //mtp feedback
i++;
Serial.println(i);
//if (i >= packet_size) {
// break;
//}
}
// }
// another print to figure out how long it took to get all the data
Serial.print("Time taken to receive data from slave: ");
Serial.print((millis() - t_request)/1000.0, 2);
Serial.println(" seconds");
// more prints
Serial.print("Number of bytes read from last transmission: "); // checking if this is less than 4.
Serial.println(i, DEC);
// JOSH: Realizing that this is a messy way to convert byte array to a float :P
// typecast the apppropiate sections on the packet
//val_1 = (float*)(&msg[0]); // extract first float
//val_2 = (float*)(&msg[4]); // extract second float
//status_msg = (char*)(&msg[8]); // extract string of text at the end
// JOSH: This should also work
memcpy(&val_1, &msg[0], sizeof(float));
//memcpy(&val_2, &msg[4], sizeof(float));
//memcpy(status_msg, &msg[8], 4);
// perform all printouts
Serial.print("value 1 is ");
Serial.print(val_1,5); //testing 4/27/19
Serial.print(", ");
//Serial.println(val_2,5); //testing 4/27/19
val_1str = String(data);
Serial.println("val1str is "+val_1str);
//Serial.print(", ");
//Serial.print(status_msg);
//Serial.print("\n");
delay(2500);
}