Problem in Adafruit HMC5883L mega sensor code
hey,
i have bought gy-271 magnetometer sensor , connected arduino uno board.
i used adafruit hmc5883l library! here
when run code , displays sensor information , not values
using print statements , backpropagating found
when removed while loop , code started working values remained constant when keep changing position of sensor
i have bought gy-271 magnetometer sensor , connected arduino uno board.
i used adafruit hmc5883l library! here
when run code , displays sensor information , not values
using print statements , backpropagating found
- in megasenosr example code , problem with getevent(), function control never returned function
code: [select]
void loop(void)
{
/* new sensor event */
sensors_event_t event; // never returned fun
mag.getevent(&event);
/* display results (magnetic vector values in micro-tesla (ut)) */
serial.print("x: "); serial.print(event.magnetic.x); serial.print(" ");
serial.print("y: "); serial.print(event.magnetic.y); serial.print(" ");
serial.print("z: "); serial.print(event.magnetic.z); serial.print(" ");serial.println("ut");
- [/li]
- going , looking @ getevent(), found fun read() never returned control
code: [select]
bool adafruit_hmc5883_unified::getevent(sensors_event_t *event) {
/* clear event */
memset(event, 0, sizeof(sensors_event_t));
/* read new data */
serial.println("going read data...");
read();//never returned here
serial.println("read data...");
event->version = sizeof(sensors_event_t);
event->sensor_id = _sensorid;
event->type = sensor_type_magnetic_field;
event->timestamp = 0;
event->magnetic.x = _magdata.x / _hmc5883_gauss_lsb_xy * sensors_gauss_to_microtesla;
event->magnetic.y = _magdata.y / _hmc5883_gauss_lsb_xy * sensors_gauss_to_microtesla;
event->magnetic.z = _magdata.z / _hmc5883_gauss_lsb_z * sensors_gauss_to_microtesla;
return true;
}
- [/li]
- going bak read function, found function never escaped out of "while(wire.available() < 6);"
code: [select]
void adafruit_hmc5883_unified::read()
{
// read magnetometer
serial.println("reading data 1 ...");
wire.begintransmission((byte)hmc5883_address_mag);
serial.println("read data 2...");
#if arduino >= 100
wire.write(hmc5883_register_mag_out_x_h_m);
serial.println("read data 3...");
#else
wire.send(hmc5883_register_mag_out_x_h_m);
serial.println("read data4...");
#endif
wire.endtransmission();
serial.println("read data 5...");
wire.requestfrom((byte)hmc5883_address_mag, (byte)6);
serial.println("read data 6...");
// wait around until enough data available
while(wire.available() < 6); // never rerturned here
serial.println("read data 7...");
// note high before low (different accel)
[/code[/li]
[/list]
when removed while loop , code started working values remained constant when keep changing position of sensor
seems have been lot safer them add timeout on code , return error code.
i'd check connections on sensor.
i'd check connections on sensor.
Arduino Forum > Using Arduino > Programming Questions > Problem in Adafruit HMC5883L mega sensor code
arduino
Comments
Post a Comment