» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » I2CFirmata ? : http://codelab.fr/5184 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : I2CFirmata ? |
top — 2014-07-15 10:07:01 |
Tout est dans le titre ou presque :lol: import processing.serial.*; import cc.arduino.*; Arduino arduino; void setup() { println(Arduino.list()[0]); arduino = new Arduino(this, Arduino.list()[0], 57600); arduino.pinMode(4, Arduino.INPUT); arduino.pinMode(5, Arduino.INPUT); } void draw() { float val1=arduino.analogRead(4); float val2=arduino.analogRead(5); println("val1= "+val1+" val2= "+val2); } Quelqu'un a-t-il un peu d'expérience avec ce protocole ? |
Mushussu — 2014-07-16 08:23:13 |
Bonjour, |
top — 2014-07-16 13:46:54 |
Merci de ta réponse |
fabrice54 — 2014-07-17 05:46:36 |
avec quel firmata a tu essayé standard ou IC2? |
top — 2014-07-17 08:43:17 |
J'ai essayé les deux avec la boussole (HMC6352), |
fabrice54 — 2014-07-18 05:48:45 |
c'est bizarre ,dans ton code essaye de supprimer les lignes " arduino.pinMode(4, Arduino.INPUT); |
fabrice54 — 2014-07-19 05:12:55 |
mettre les informations concernant ton capteur dans Firmata standard la ou tu vas voir les lignes suivantes. |
top — 2014-07-19 08:07:21 |
Bon j'ai fait quelques tests sans passer par standardFirmata en utilisant le code |
fabrice54 — 2014-07-20 07:38:50 |
bonjour. Code (P5) :#include <Wire.h> void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output Serial.println(); // Print a banner Serial.println(); Serial.println("I2C slave scanner"); Serial.println(" reserved adress"); Serial.println(". no slave detected"); Serial.println("X slave detected"); Serial.println(); Serial.println(); int result; Serial.println(" 0 1 2 3 4 5 6 7 8 9 A B C D E F"); // Scan only valid addresses (8 to 0x7B) // 0-7 and 7C-7F are reserved ones unsigned char devices=0; // holds how many devices found for (unsigned char ad=0; ad<0x7C;ad++){ if(ad%16==0){ // If at start of a row Serial.print(ad>>4,HEX); // Display high order bit address Serial.print(" "); } if (ad>7){ // skip address from 0 to 7 Wire.beginTransmission(ad); // start transmission result = Wire.endTransmission(); // end transmission and store answer if (!result) devices++; // add a device to the count if ACK Serial.print(" "); Serial.print(result==0?"X ":". "); // If ACK there is a guy at this address } else{ Serial.print(" "); // Sorry nobody here } if(ad%16==15) Serial.println(); // end of the row add a new line } Serial.println(); Serial.println(); Serial.println(); Serial.print(devices, DEC); Serial.print(" device"); Serial.print(devices>1?"s":""); Serial.println(" found on the bus"); } void loop() { } |
fabrice54 — 2014-07-20 08:12:16 |
Un programme pour le compas CMP S03.compare avec le tien. Code (P5) :#include <Wire.h> #define ADDRESS 0x60 //defines address of compass void setup(){ Wire.begin(); //conects I2C Serial.begin(9600); } void loop(){ byte highByte; byte lowByte; Wire.beginTransmission(ADDRESS); //starts communication with cmps03 Wire.write(2); //Sends the register we wish to read Wire.endTransmission(); Wire.requestFrom(ADDRESS, 2); //requests high byte while(Wire.available() < 2); //while there is a byte to receive highByte = Wire.read(); //reads the byte as an integer lowByte = Wire.read(); int bearing = ((highByte<<8)+lowByte)/10; Serial.println(bearing); delay(100); } |
top — 2014-07-20 09:08:11 |
Aie Aie |
fabrice54 — 2014-07-21 05:30:22 |
Tu es sur que ton circuit n'as pas un Default ?c'est pas normal;si tu as un oscillo tu peut tester pour être sur .Il m'ait |
fabrice54 — 2014-07-21 05:36:28 |
Je viens de voir un truc ,tu es sur que ton circuit n'est pas en mode sommeil?. |
fabrice54 — 2014-07-21 06:13:50 |
test ce code.il faut virer les lignes qui concerne liquide cristal. Code (P5) :#include<Wire.h> #include <LiquidCrystal.h> int HMC6352Address = 0x42; // This is calculated in the setup() function int slaveAddress; int ledPin = 13; int ledPin2 = 2; int ledPin3 = 3; int ledPin10 = 10; boolean ledState = false; byte headingData[2]; int i, headingValue; LiquidCrystal lcd(8,9,4,5,6,7); void setup() { // Shift the device's documented slave address (0x42) 1 bit right // This compensates for how the TWI library only wants the // 7 most significant bits (with the high bit padded with 0) slaveAddress = HMC6352Address >> 1; // This results in 0x21 as the address to pass to TWI Serial.begin(9600); pinMode(ledPin, OUTPUT); // Set the LED pin as output Wire.begin(); lcd.begin(8,2); } void loop() { // Flash the LED on pin 13 just to show that something is happening // Also serves as an indication that we're not "stuck" waiting for TWI data ledState = !ledState; if (ledState) { digitalWrite(ledPin,HIGH); } else { digitalWrite(ledPin,LOW); } // Send a "A" command to the HMC6352 // This requests the current heading data Wire.beginTransmission(slaveAddress); Wire.write("A"); // The "Get Data" command Wire.endTransmission(); delay(10); // The HMC6352 needs at least a 70us (microsecond) delay // after this command. Using 10ms just makes it safe // Read the 2 heading bytes, MSB first // The resulting 16bit word is the compass heading in 10th's of a degree // For example: a heading of 1345 would be 134.5 degrees Wire.requestFrom(slaveAddress, 2); // Request the 2 byte heading (MSB comes first) i = 0; while(Wire.available() && i < 2) { headingData[i] = Wire.read(); i++; } headingValue = headingData[0]*256 + headingData[1]; // Put the MSB and LSB together int gradi = int(headingValue / 10); int fraction = int(headingValue % 10); lcd.clear(); Serial.print("Current heading: "); Serial.print(gradi); lcd.print(gradi); // The whole number part of the heading Serial.print("."); lcd.write('.'); Serial.print(fraction); lcd.print(fraction); // The fractional part of the heading Serial.print(" degrees Direction: "); lcd.print("deg"); lcd.setCursor(1,1); if ((gradi >= 337 && gradi <= 359) || (gradi >= 0 && gradi < 22)) { Serial.println("N"); lcd.print("North"); digitalWrite(ledPin2, HIGH); delay(100); digitalWrite(ledPin2, LOW);} else if (gradi >= 292 && gradi <= 336) { Serial.println("NW"); lcd.print("N-West"); digitalWrite(ledPin3, HIGH); delay(100); digitalWrite(ledPin3, LOW);} else if (gradi >= 252 && gradi <= 291) { Serial.println("W"); lcd.print("West"); digitalWrite(ledPin10, HIGH); delay(100); digitalWrite(ledPin10, LOW);} else if (gradi >= 207 && gradi <= 251) { Serial.println("SW"); lcd.print("S-West");} else if (gradi >= 157 && gradi <= 206) { Serial.println("S"); lcd.print("South");} else if (gradi >= 112 && gradi <= 156) { Serial.println("SE"); lcd.print("S-East");} else if (gradi >= 67 && gradi <= 111) { Serial.println("E"); lcd.print("East");} else if (gradi >= 22 && gradi <= 66) { Serial.println("NE"); lcd.print("N-East");} else Serial.println(""); delay(500); } |