Bonjour,
Nous utilisons une arduino Teemino + un NX Shield,
Nous arrivons a utiliser tous les capteurs de lego, mais avons juste un probléme sur le capteur en rotation
Nous utilisons ce code, avec les bilbliotheques fournis :
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
For beginners tutorial (and user guide) visit:
http://www.openelectrons.com/docs/viewdoc/1
*/
#include <Wire.h>
#include <NXShield.h>
#include <AngleSensor.h>
// setup for this example:
// attach external power to NXShield.
// attach AngleSensor to Port BAS1
// Open the Serial terminal to view.
//
// declare the NXShield(s) attached to your Arduino.
//
NXShield nxshield;
//
// declare the i2c devices used on NXShield(s).
//
AngleSensor angsens (0x30);
void setup()
{
char str[256];
/** Start serial for output
*/
Serial.begin(115200); //
/** Wait, allowing time to activate the serial monitor
*/
delay(500); // wait, allowing time to activate the serial monitor
/** Initialize the protocol for NXShield
It is best to use Hardware I2C (unless you want to use Ultrasonic).
*/
nxshield.init( SH_SoftwareI2C );
/** Wait until user presses GO button to continue the program
*/
Serial.println ("Press GO button to continue");
nxshield.waitForButtonPress(BTN_GO);
/** Initialize the i2c sensors.
*/
angsens.init( &nxshield, SH_BAS1 );
}
#define DELAY_T 0
void loop()
{
char aa[80];
char str[256]; //sets length of character string
uint8_t result;
char str2[20]; //sets length of character string 2
char str3[20]; //sets length of character string 3
long angle; //declares "angle" variable
long myread; //declares "myread" variable
/** Displays Firmeware Version of sensor
*/
strcpy(aa, angsens.getFirmwareVersion() );
sprintf (str, "angsens: getFirmwareVersion: %s", aa);
Serial.println(str);
/** Displays Device ID of sensor
*/
strcpy(aa, angsens.getDeviceID() );
sprintf (str, "angsens: DeviceID: %s", aa);
Serial.println(str);
/** Gets and displays Vendor ID of sensor
*/
strcpy(aa, angsens.getVendorID() );
sprintf (str, "angsens: VendorID: %s", aa);
Serial.println(str);
/** Displays Angle
*/
angle = angsens.getAngle();
sprintf (str, "angsens: Angle: %ld", angle);
Serial.println(str);
/** Displays Raw Reading
*/
myread = angsens.getRawReading();
sprintf (str, "angsens: Raw Reading: %ld", myread);
Serial.println(str);
Serial.println( "-------------" );
delay (1500);
}
le probléme c est que la carte ne semble pas detecter le capteur :
voyez vous un element dans le code qui fait que l on ne detecte pas le capteur ? ou des points a verifier pour etre sur que ca marche ?
Merci d avance