Show Posts
Pages: 1 2 [3] 4 5 ... 44
31  International / Generale / Re: neo utilizzatore di accelerometro ADXL345 on: July 04, 2014, 06:29:04 am
Ciao
Se ti riferisci al post nella sezione Hardware, quello è un altro problema, ero convinto si potesse fare, mi spiace se sto facendo confusione, ho provato a cancellare questo ma il forum non me lo consente.

Stefano
32  International / Hardware / Re: ADXL345 con valore di registro diverso dal datasheet on: July 04, 2014, 06:23:27 am
Ciao
Ho letto il datasheet e come detto l'indirizzo viene indicato come solo Read, ho provato, non si può scrivere

Stefano
33  International / Hardware / ADXL345 con valore di registro diverso dal datasheet on: July 04, 2014, 02:21:11 am
Ciao
Ho 3 accelerometri, acquistati su geetech, stavo sperimentando facendo le letture dei registri all'indirizzo 0x30, di sola lettura, su uno  leggo un byte [ 10000011 ], mentre sugli altri due leggo [ 10000010 ], entrambi diversi da quello indicato nel datasheet [ 00000010 ].
E' possibile?

Stefano
34  International / Software / Re: come stampare stringhe on: July 04, 2014, 01:01:16 am
ciao
grazie, questa è la modifica funzionante:
Code:
/*

 */
#define ADXL345_REG_DEVID               (0x00)    // Device ID
#define ADXL345_REG_THRESH_TAP          (0x1D)    // Tap threshold
#define ADXL345_REG_OFSX                (0x1E)    // X-axis offset
#define ADXL345_REG_OFSY                (0x1F)    // Y-axis offset
#define ADXL345_REG_OFSZ                (0x20)    // Z-axis offset
#define ADXL345_REG_DUR                 (0x21)    // Tap duration
#define ADXL345_REG_LATENT              (0x22)    // Tap latency
#define ADXL345_REG_WINDOW              (0x23)    // Tap window
#define ADXL345_REG_THRESH_ACT          (0x24)    // Activity threshold
#define ADXL345_REG_THRESH_INACT        (0x25)    // Inactivity threshold
#define ADXL345_REG_TIME_INACT          (0x26)    // Inactivity time
#define ADXL345_REG_ACT_INACT_CTL       (0x27)    // Axis enable control for activity and inactivity detection
#define ADXL345_REG_THRESH_FF           (0x28)    // Free-fall threshold
#define ADXL345_REG_TIME_FF             (0x29)    // Free-fall time
#define ADXL345_REG_TAP_AXES            (0x2A)    // Axis control for single/double tap
#define ADXL345_REG_ACT_TAP_STATUS      (0x2B)    // Source for single/double tap
#define ADXL345_REG_BW_RATE             (0x2C)    // Data rate and power mode control
#define ADXL345_REG_POWER_CTL           (0x2D)    // Power-saving features control
#define ADXL345_REG_INT_ENABLE          (0x2E)    // Interrupt enable control
#define ADXL345_REG_INT_MAP             (0x2F)    // Interrupt mapping control
#define ADXL345_REG_INT_SOURCE          (0x30)    // Source of interrupts
#define ADXL345_REG_DATA_FORMAT         (0x31)    // Data format control
#define ADXL345_REG_DATAX0              (0x32)    // X-axis data 0
#define ADXL345_REG_DATAX1              (0x33)    // X-axis data 1
#define ADXL345_REG_DATAY0              (0x34)    // Y-axis data 0
#define ADXL345_REG_DATAY1              (0x35)    // Y-axis data 1
#define ADXL345_REG_DATAZ0              (0x36)    // Z-axis data 0
#define ADXL345_REG_DATAZ1              (0x37)    // Z-axis data 1
#define ADXL345_REG_FIFO_CTL            (0x38)    // FIFO control
#define ADXL345_REG_FIFO_STATUS         (0x39)    // FIFO status
/*=========================================================================*/

#define TO_READ (30)//num of bytes we are going to read each time

char* reg[] = {   
    "ADXL345_REG_DEVID",
    "ADXL345_REG_THRESH_TAP",
    "ADXL345_REG_OFSX",
    "ADXL345_REG_OFSY",
    "ADXL345_REG_OFSZ",
    "ADXL345_REG_DUR",
    "ADXL345_REG_LATENT",
    "ADXL345_REG_WINDOW",
    "ADXL345_REG_THRESH_ACT",
    "ADXL345_REG_THRESH_INACT",
    "ADXL345_REG_TIME_INACT",
    "ADXL345_REG_ACT_INACT_CTL",
    "ADXL345_REG_THRESH_FF",
    "ADXL345_REG_TIME_FF",
    "ADXL345_REG_TAP_AXES",
    "ADXL345_REG_ACT_TAP_STATUS",
    "ADXL345_REG_BW_RATE",
    "ADXL345_REG_POWER_CTL",
    "ADXL345_REG_INT_ENABLE",
    "ADXL345_REG_INT_MAP",
    "ADXL345_REG_INT_SOURCE",
    "ADXL345_REG_DATA_FORMAT",
    "ADXL345_REG_DATAX0",
    "ADXL345_REG_DATAX1",
    "ADXL345_REG_DATAY0",
    "ADXL345_REG_DATAY1",
    "ADXL345_REG_DATAZ0",
    "ADXL345_REG_DATAZ1",
    "ADXL345_REG_FIFO_CTL",
    "ADXL345_REG_FIFO_STATUS",
    '\0'
  };

void setup()
{

  Serial.begin(9600);  // start serial for output


}

void loop()
{
  Serial.println("START");
  for(int k = 0; k < TO_READ; k++)
  {

  Serial.print(k);
  Serial.print('\t');
  Serial.print(reg[k]);

  Serial.println();
  delay(10);//It appears that delay is needed in order not to clog the port
  }
 
   delay(50);
}//fine loop

sempre disponibili come sempre

Stefano
35  International / Software / Re: come stampare stringhe on: July 04, 2014, 12:16:43 am
ciao
questo è l'esempio del reference da dove cui sono partito:
Code:
Example


char* myStrings[]={"This is string 1", "This is string 2", "This is string 3",
"This is string 4", "This is string 5","This is string 6"};

void setup(){
Serial.begin(9600);
}

void loop(){
for (int i = 0; i < 6; i++){
   Serial.println(myStrings[i]);
   delay(500);
   }
}

e questo il codice ripulito che sto provando:
Code:
/*

 */
#define ADXL345_REG_DEVID               (0x00)    // Device ID
#define ADXL345_REG_THRESH_TAP          (0x1D)    // Tap threshold
#define ADXL345_REG_OFSX                (0x1E)    // X-axis offset
#define ADXL345_REG_OFSY                (0x1F)    // Y-axis offset
#define ADXL345_REG_OFSZ                (0x20)    // Z-axis offset
#define ADXL345_REG_DUR                 (0x21)    // Tap duration
#define ADXL345_REG_LATENT              (0x22)    // Tap latency
#define ADXL345_REG_WINDOW              (0x23)    // Tap window
#define ADXL345_REG_THRESH_ACT          (0x24)    // Activity threshold
#define ADXL345_REG_THRESH_INACT        (0x25)    // Inactivity threshold
#define ADXL345_REG_TIME_INACT          (0x26)    // Inactivity time
#define ADXL345_REG_ACT_INACT_CTL       (0x27)    // Axis enable control for activity and inactivity detection
#define ADXL345_REG_THRESH_FF           (0x28)    // Free-fall threshold
#define ADXL345_REG_TIME_FF             (0x29)    // Free-fall time
#define ADXL345_REG_TAP_AXES            (0x2A)    // Axis control for single/double tap
#define ADXL345_REG_ACT_TAP_STATUS      (0x2B)    // Source for single/double tap
#define ADXL345_REG_BW_RATE             (0x2C)    // Data rate and power mode control
#define ADXL345_REG_POWER_CTL           (0x2D)    // Power-saving features control
#define ADXL345_REG_INT_ENABLE          (0x2E)    // Interrupt enable control
#define ADXL345_REG_INT_MAP             (0x2F)    // Interrupt mapping control
#define ADXL345_REG_INT_SOURCE          (0x30)    // Source of interrupts
#define ADXL345_REG_DATA_FORMAT         (0x31)    // Data format control
#define ADXL345_REG_DATAX0              (0x32)    // X-axis data 0
#define ADXL345_REG_DATAX1              (0x33)    // X-axis data 1
#define ADXL345_REG_DATAY0              (0x34)    // Y-axis data 0
#define ADXL345_REG_DATAY1              (0x35)    // Y-axis data 1
#define ADXL345_REG_DATAZ0              (0x36)    // Z-axis data 0
#define ADXL345_REG_DATAZ1              (0x37)    // Z-axis data 1
#define ADXL345_REG_FIFO_CTL            (0x38)    // FIFO control
#define ADXL345_REG_FIFO_STATUS         (0x39)    // FIFO status
/*=========================================================================*/

#define TO_READ (30)//num of bytes we are going to read each time

char reg[30];

void setup()
{

  Serial.begin(9600);  // start serial for output

char* reg[] = {
    "ADXL345_REG_DEVID",
    "ADXL345_REG_THRESH_TAP",
    "ADXL345_REG_OFSX",
    "ADXL345_REG_OFSY",
    "ADXL345_REG_OFSZ",
    "ADXL345_REG_DUR",
    "ADXL345_REG_LATENT",
    "ADXL345_REG_WINDOW",
    "ADXL345_REG_THRESH_ACT",
    "ADXL345_REG_THRESH_INACT",
    "ADXL345_REG_TIME_INACT",
    "ADXL345_REG_ACT_INACT_CTL",
    "ADXL345_REG_THRESH_FF",
    "ADXL345_REG_TIME_FF",
    "ADXL345_REG_TAP_AXES",
    "ADXL345_REG_ACT_TAP_STATUS",
    "ADXL345_REG_BW_RATE",
    "ADXL345_REG_POWER_CTL",
    "ADXL345_REG_INT_ENABLE",
    "ADXL345_REG_INT_MAP",
    "ADXL345_REG_INT_SOURCE",
    "ADXL345_REG_DATA_FORMAT",
    "ADXL345_REG_DATAX0",
    "ADXL345_REG_DATAX1",
    "ADXL345_REG_DATAY0",
    "ADXL345_REG_DATAY1",
    "ADXL345_REG_DATAZ0",
    "ADXL345_REG_DATAZ1",
    "ADXL345_REG_FIFO_CTL",
    "ADXL345_REG_FIFO_STATUS"
  };
}

void loop()
{
  Serial.println("START");
  for(int k = 0; k < TO_READ; k++)
  {

  Serial.print(k);
  Serial.print('\t');
  Serial.print(reg[k]);

  Serial.println();
  delay(10);//It appears that delay is needed in order not to clog the port
  }
 
   delay(50);
}//fine loop

a me sembrano uguali, non capisco cosa mi sfugge
36  International / Software / Re: come stampare stringhe on: July 03, 2014, 02:39:05 pm
ciao
lo sketch funziona, dopo il read...
k viene stampato
reg[k] non viene stampato
buff[k] viene stampato
37  International / Generale / Re: neo utilizzatore di accelerometro ADXL345 on: July 03, 2014, 01:43:17 pm
ciao
sono riuscito, finalmente, a comprendere le operazioni che vengono eseguite in questo codice, ma i valori che restituisce sono errati, ho letto che devo fare una calibrazioni, ho seguito alcune guide me ancora nessun risultato, nessuno ha fatto esperienze con questo sensore, nella sezione megatopic si parla di quadricotteri, ma non ho trovato suggerimenti

Stefano
38  International / Software / Re: come stampare stringhe on: July 03, 2014, 01:33:53 pm
ciao
grazie per la risposta è tutto oggi che provo, ma quello che mi serve al momento è proprio stampare il contenuto delle "", non riuscire a stampare il contenuto del tag è l'altro problema, allego tutto il codice
Code:
/*
I2C comunication
 
 CS pin 3v3
 SDA pin SDA +10k to 3v3
 SDO pin GND
 SCL pin SCL +10k to 3v3
 3v3 VCC
 GND GND
 */
#define ADXL345_REG_DEVID               (0x00)    // Device ID
#define ADXL345_REG_THRESH_TAP          (0x1D)    // Tap threshold
#define ADXL345_REG_OFSX                (0x1E)    // X-axis offset
#define ADXL345_REG_OFSY                (0x1F)    // Y-axis offset
#define ADXL345_REG_OFSZ                (0x20)    // Z-axis offset
#define ADXL345_REG_DUR                 (0x21)    // Tap duration
#define ADXL345_REG_LATENT              (0x22)    // Tap latency
#define ADXL345_REG_WINDOW              (0x23)    // Tap window
#define ADXL345_REG_THRESH_ACT          (0x24)    // Activity threshold
#define ADXL345_REG_THRESH_INACT        (0x25)    // Inactivity threshold
#define ADXL345_REG_TIME_INACT          (0x26)    // Inactivity time
#define ADXL345_REG_ACT_INACT_CTL       (0x27)    // Axis enable control for activity and inactivity detection
#define ADXL345_REG_THRESH_FF           (0x28)    // Free-fall threshold
#define ADXL345_REG_TIME_FF             (0x29)    // Free-fall time
#define ADXL345_REG_TAP_AXES            (0x2A)    // Axis control for single/double tap
#define ADXL345_REG_ACT_TAP_STATUS      (0x2B)    // Source for single/double tap
#define ADXL345_REG_BW_RATE             (0x2C)    // Data rate and power mode control
#define ADXL345_REG_POWER_CTL           (0x2D)    // Power-saving features control
#define ADXL345_REG_INT_ENABLE          (0x2E)    // Interrupt enable control
#define ADXL345_REG_INT_MAP             (0x2F)    // Interrupt mapping control
#define ADXL345_REG_INT_SOURCE          (0x30)    // Source of interrupts
#define ADXL345_REG_DATA_FORMAT         (0x31)    // Data format control
#define ADXL345_REG_DATAX0              (0x32)    // X-axis data 0
#define ADXL345_REG_DATAX1              (0x33)    // X-axis data 1
#define ADXL345_REG_DATAY0              (0x34)    // Y-axis data 0
#define ADXL345_REG_DATAY1              (0x35)    // Y-axis data 1
#define ADXL345_REG_DATAZ0              (0x36)    // Z-axis data 0
#define ADXL345_REG_DATAZ1              (0x37)    // Z-axis data 1
#define ADXL345_REG_FIFO_CTL            (0x38)    // FIFO control
#define ADXL345_REG_FIFO_STATUS         (0x39)    // FIFO status
/*=========================================================================*/
#include <Wire.h>

#define DEVICE (0x53)//ADXL345 device address
#define TO_READ (28)//num of bytes we are going to read each time

byte buff[TO_READ];    //n bytes buffer for saving data read from the device
int ADXL345_REG_ = 0x1D;//indirizzo di partenza;
char reg[TO_READ];
byte reg_[TO_READ];

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

/*  //Turning on the ADXL345
  writeTo(DEVICE, 0x2D, 0);     
  writeTo(DEVICE, 0x2D, 16);
  writeTo(DEVICE, 0x2D, 8);
*/ 
    //Turning on the ADXL345       
  writeTo(DEVICE, 0x31, 0x0B);
  writeTo(DEVICE, 0x2D, 0x08);
  writeTo(DEVICE, 0x2E, 0x80);
/*
char* reg[] = {
    "ADXL345_REG_DEVID",
    "ADXL345_REG_THRESH_TAP",
    "ADXL345_REG_OFSX",
    "ADXL345_REG_OFSY",
    "ADXL345_REG_OFSZ",
    "ADXL345_REG_DUR",
    "ADXL345_REG_LATENT",
    "ADXL345_REG_WINDOW",
    "ADXL345_REG_THRESH_ACT",
    "ADXL345_REG_THRESH_INACT",
    "ADXL345_REG_TIME_INACT",
    "ADXL345_REG_ACT_INACT_CTL",
    "ADXL345_REG_THRESH_FF",
    "ADXL345_REG_TIME_FF",
    "ADXL345_REG_TAP_AXES",
    "ADXL345_REG_ACT_TAP_STATUS",
    "ADXL345_REG_BW_RATE",
    "ADXL345_REG_POWER_CTL",
    "ADXL345_REG_INT_ENABLE",
    "ADXL345_REG_INT_MAP",
    "ADXL345_REG_INT_SOURCE",
    "ADXL345_REG_DATA_FORMAT",
    "ADXL345_REG_DATAX0",
    "ADXL345_REG_DATAX1",
    "ADXL345_REG_DATAY0",
    "ADXL345_REG_DATAY1",
    "ADXL345_REG_DATAZ0",
    "ADXL345_REG_DATAZ1",
    "ADXL345_REG_FIFO_CTL",
    "ADXL345_REG_FIFO_STATUS"  }; 
*/
/*
byte* reg_[] = {
  //  ADXL345_REG_DEVID,
    ADXL345_REG_THRESH_TAP},
    ADXL345_REG_OFSX,
    ADXL345_REG_OFSY,
    ADXL345_REG_OFSZ,
    ADXL345_REG_DUR,
    ADXL345_REG_LATENT,
    ADXL345_REG_WINDOW,
    ADXL345_REG_THRESH_ACT,
    ADXL345_REG_THRESH_INACT,
    ADXL345_REG_TIME_INACT,
    ADXL345_REG_ACT_INACT_CTL,
    ADXL345_REG_THRESH_FF,
    ADXL345_REG_TIME_FF,
    ADXL345_REG_TAP_AXES,
    ADXL345_REG_ACT_TAP_STATUS,
    ADXL345_REG_BW_RATE,
    ADXL345_REG_POWER_CTL,
    ADXL345_REG_INT_ENABLE,
    ADXL345_REG_INT_MAP,
    ADXL345_REG_INT_SOURCE,
    ADXL345_REG_DATA_FORMAT,
    ADXL345_REG_DATAX0,
    ADXL345_REG_DATAX1,
    ADXL345_REG_DATAY0,
    ADXL345_REG_DATAY1,
    ADXL345_REG_DATAZ0,
    ADXL345_REG_DATAZ1,
    ADXL345_REG_FIFO_CTL,
    ADXL345_REG_FIFO_STATUS }; 
*/
}

void loop()
{
  Serial.println("START");
  for(int k = 0; k < TO_READ; k++)
  {
  readFrom(DEVICE, ADXL345_REG_, TO_READ, buff); //read the acceleration data from the ADXL345
 
  Serial.print(k);
  Serial.print('\t');
 // Serial.print(reg[k], HEX);
 // Serial.print('\t');
  Serial.print(buff[k], BIN);
  Serial.println();
  delay(10);//It appears that delay is needed in order not to clog the port
  }
 
 // readByte(DEVICE, ADXL345_REG_);
  // Serial.println(int(readByte), BIN);*/

  delay(50);//It appears that delay is needed in order not to clog the port
}//fine loop

void writeTo(int device, byte address, byte val) {
  Wire.beginTransmission(device); //start transmission to device
  Wire.write(address);        // send register address
  Wire.write(val);        // send value to write
  Wire.endTransmission(); //end transmission
}

void readFrom(int device, byte address, int num, byte buff[]) {
  Wire.beginTransmission(device); //start transmission to device
  Wire.write(address);        //sends address to read from
  Wire.endTransmission(); //end transmission

    Wire.beginTransmission(device); //start transmission to device (initiate again)
  Wire.requestFrom(device, num);    // request 6 bytes from device

  int i = 0;
  while(Wire.available())    //device may send less than requested (abnormal)
  {
    buff[i] = Wire.read(); // receive a byte
    i++;
  }
  Wire.endTransmission(); //end transmission
}
39  International / Software / [risolto] come stampare stringhe on: July 03, 2014, 11:46:47 am
Ciao
Sto cercando di stampare questo vettore di stringhe, ma senza risultato, ho seguito il semplice esempio del Reference, ma senza risultato.
Avete qualche suggerimento.

Grazie
Stefano
Code:
/*

 */
#define ADXL345_REG_DEVID               (0x00)    // Device ID
#define ADXL345_REG_THRESH_TAP          (0x1D)    // Tap threshold
#define ADXL345_REG_OFSX                (0x1E)    // X-axis offset
#define ADXL345_REG_OFSY                (0x1F)    // Y-axis offset
#define ADXL345_REG_OFSZ                (0x20)    // Z-axis offset
#define ADXL345_REG_DUR                 (0x21)    // Tap duration
#define ADXL345_REG_LATENT              (0x22)    // Tap latency
#define ADXL345_REG_WINDOW              (0x23)    // Tap window
#define ADXL345_REG_THRESH_ACT          (0x24)    // Activity threshold
#define ADXL345_REG_THRESH_INACT        (0x25)    // Inactivity threshold
#define ADXL345_REG_TIME_INACT          (0x26)    // Inactivity time
#define ADXL345_REG_ACT_INACT_CTL       (0x27)    // Axis enable control for activity and inactivity detection
#define ADXL345_REG_THRESH_FF           (0x28)    // Free-fall threshold
#define ADXL345_REG_TIME_FF             (0x29)    // Free-fall time
#define ADXL345_REG_TAP_AXES            (0x2A)    // Axis control for single/double tap
#define ADXL345_REG_ACT_TAP_STATUS      (0x2B)    // Source for single/double tap
#define ADXL345_REG_BW_RATE             (0x2C)    // Data rate and power mode control
#define ADXL345_REG_POWER_CTL           (0x2D)    // Power-saving features control
#define ADXL345_REG_INT_ENABLE          (0x2E)    // Interrupt enable control
#define ADXL345_REG_INT_MAP             (0x2F)    // Interrupt mapping control
#define ADXL345_REG_INT_SOURCE          (0x30)    // Source of interrupts
#define ADXL345_REG_DATA_FORMAT         (0x31)    // Data format control
#define ADXL345_REG_DATAX0              (0x32)    // X-axis data 0
#define ADXL345_REG_DATAX1              (0x33)    // X-axis data 1
#define ADXL345_REG_DATAY0              (0x34)    // Y-axis data 0
#define ADXL345_REG_DATAY1              (0x35)    // Y-axis data 1
#define ADXL345_REG_DATAZ0              (0x36)    // Z-axis data 0
#define ADXL345_REG_DATAZ1              (0x37)    // Z-axis data 1
#define ADXL345_REG_FIFO_CTL            (0x38)    // FIFO control
#define ADXL345_REG_FIFO_STATUS         (0x39)    // FIFO status
/*=========================================================================*/

#define TO_READ (30)//num of bytes we are going to read each time

char reg[30];

void setup()
{

  Serial.begin(9600);  // start serial for output


char* reg[] = {
    "ADXL345_REG_DEVID",
    "ADXL345_REG_THRESH_TAP",
    "ADXL345_REG_OFSX",
    "ADXL345_REG_OFSY",
    "ADXL345_REG_OFSZ",
    "ADXL345_REG_DUR",
    "ADXL345_REG_LATENT",
    "ADXL345_REG_WINDOW",
    "ADXL345_REG_THRESH_ACT",
    "ADXL345_REG_THRESH_INACT",
    "ADXL345_REG_TIME_INACT",
    "ADXL345_REG_ACT_INACT_CTL",
    "ADXL345_REG_THRESH_FF",
    "ADXL345_REG_TIME_FF",
    "ADXL345_REG_TAP_AXES",
    "ADXL345_REG_ACT_TAP_STATUS",
    "ADXL345_REG_BW_RATE",
    "ADXL345_REG_POWER_CTL",
    "ADXL345_REG_INT_ENABLE",
    "ADXL345_REG_INT_MAP",
    "ADXL345_REG_INT_SOURCE",
    "ADXL345_REG_DATA_FORMAT",
    "ADXL345_REG_DATAX0",
    "ADXL345_REG_DATAX1",
    "ADXL345_REG_DATAY0",
    "ADXL345_REG_DATAY1",
    "ADXL345_REG_DATAZ0",
    "ADXL345_REG_DATAZ1",
    "ADXL345_REG_FIFO_CTL",
    "ADXL345_REG_FIFO_STATUS"
  };
}

void loop()
{
  Serial.println("START");
  for(int k = 0; k < TO_READ; k++)
  {

  Serial.print(k);
  Serial.print('\t');
  Serial.print(reg[k]);

  Serial.println();
  delay(10);//It appears that delay is needed in order not to clog the port
  }
  
   delay(50);
}//fine loop
40  International / Generale / Re: Segnalazione di problemi legati al forum on: July 03, 2014, 11:42:29 am
Ciao
Volevo capire/segnalare, da diversi giorni devo ricaricare più di una volta le pagine di Arduino, volevo sapere se è un problema legato al forum oppure un problema del nuovo pc, i problemi sono iniziati circa da quel momento.

Grazie

Stefano
41  International / Generale / neo utilizzatore di accelerometro ADXL345 on: July 01, 2014, 12:27:23 pm
ciao
vi scrivo per sapere se c'è qualcuno che ha avuto modo di cimentarsi con l'uso del sensore ADXL345, ci lavoro da qualche giorno, con questo sketch
Code:
/*
I2C comunication
 read acceleration value
 
 CS pin 3v3
 SDA pin SDA +10k to 3v3
 SDO pin GND
 SCL pin SCL +10k to 3v3
 3v3 VCC
 GND GND
 */

#include <Wire.h>
#define DEVICE (0x53)    //ADXL345 device address
#define TO_READ (2)        //num of bytes we are going to read each time (two bytes for each axis)

byte buff[TO_READ] ;    //6 bytes buffer for saving data read from the device
char str[512];                      //string buffer to transform data before sending it to the serial port

int regAddress;
int x, y, z;

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

  //Turning on the ADXL345
  writeTo(DEVICE, 0x2D, 0);     
  writeTo(DEVICE, 0x2D, 16);
  writeTo(DEVICE, 0x2D, 8);

  regAddress = 0x32;    //first axis-acceleration-data register on the ADXL345

}

void loop()

  readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345

  //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
  //thus we are converting both bytes in to one int
  x = (((int)buff[1]) << 8) | buff[0];   
  y = (((int)buff[3])<< 8) | buff[2];
  z = (((int)buff[5]) << 8) | buff[4];

  /*  //we send the x y z values as a string to the serial port
   sprintf(str, "%d %d %d", x, y, z); 
   Serial.print(str);
   Serial.write(10);
   
   delay(15);//It appears that delay is needed in order not to clog the port
   */
  //Print the results to the terminal.
    Serial.println("buff[1] << 8, BIN");
  Serial.println(buff[1] << 8, BIN);
  Serial.println("buff[0], BIN");
  Serial.println(buff[0], BIN);
 

  Serial.println("buff[1] << 8 | buff[0], BIN");
  Serial.println(buff[1] << 8 | buff[0], BIN);
 
  Serial.println("x, BIN");
  Serial.println(x, BIN);
 Serial.println("x, DEC");
  Serial.println(x, DEC);
  /*  Serial.print('\t');
   
   Serial.print(y * 0.00390625, DEC);
   Serial.print('\t');
   
   Serial.print(z * 0.00390625, DEC);
   Serial.print('\t');
   
   Serial.println("m/sec2");   */
  delay(20);//It appears that delay is needed in order not to clog the port

}

void writeTo(int device, byte address, byte val) {
  Wire.beginTransmission(device); //start transmission to device
  Wire.write(address);        // send register address
  Wire.write(val);        // send value to write
  Wire.endTransmission(); //end transmission
}

void readFrom(int device, byte address, int num, byte buff[]) {
  Wire.beginTransmission(device); //start transmission to device
  Wire.write(address);        //sends address to read from
  Wire.endTransmission(); //end transmission

    Wire.beginTransmission(device); //start transmission to device (initiate again)
  Wire.requestFrom(device, num);    // request 6 bytes from device

  int i = 0;
  while(Wire.available())    //device may send less than requested (abnormal)
  {
    buff[i] = Wire.read(); // receive a byte
  //  Serial.print(i);
  //  Serial.print('\t');
  //  Serial.println(buff[i], BIN);

    i++;
  }
  Wire.endTransmission(); //end transmission
}

non ho avuto grossi problemi, mettendo dei serial qua e la ho avuto modo capire qualcosa, quello che non capisco è l'utilizzo di << e |, dal reference ho capito come funzionano, ma se provo ad applicare allo sketch non capisco perchè ottengo altri risultati, sicuramente sbaglio io, avete qualche indicazione.

Grazie
Stefano
42  International / Hardware / Re: sensori per banco prova on: June 29, 2014, 04:46:28 am
ciao
giusto non lo avevo specificato, i valori di uscita devi misurarli con un tester, SOLO dopo pensare al collegamento ad arduino
43  International / Hardware / Re: sensori per banco prova on: June 29, 2014, 04:15:05 am
ciao
AnalogIN di arduino al max 5v, se sai come alimentarlo, collegalo e provalo con diversi valori di pressione, potrebbe anche avere una uscita in corrente.
Comunque arduino può andare bene, per iniziare

Stefano
44  International / Hardware / Re: sensori per banco prova on: June 29, 2014, 12:21:51 am
ciao
senza datasheet l'unica alternativa come detto è fare delle prove, individua i fili della alimentazione alimentalo mettilo sotto pressione e vedi cosa esce dai contatti che restano quindi fatti una tabella pressione/tensione o corrente

Stefano
45  International / Hardware / Re: si può fare un gps preciso al centimetro? on: June 28, 2014, 05:53:26 am
ciao
grazie per le risposte, appena finisco l'applicazione a cui sto' lavorando, vorrei provare a realizzare un sistema composto da 3 ricevitori fissi, che comunichino con la unità centrale mobile mediante radiotrasmissione, a quali dati bisogna prestare attenzione? Quale gps mi consigliate?

Stefano
Pages: 1 2 [3] 4 5 ... 44