Show Posts
Pages: 1 [2] 3 4 ... 19
16  Using Arduino / Programming Questions / Re: Bit stuck on bit manipulations ? on: February 28, 2014, 02:39:39 pm
PS, this is the I2C request and response:
17  Using Arduino / Programming Questions / Bit stuck on bit manipulations ? on: February 28, 2014, 02:29:44 pm
Hi,

Wondering if I may ask for a little help with this bit maniulation problem?

I have an I2C sensor which returns 4 bytes but I need to extract 14 bits from the first two and 11 bits from the second two:

Byte 1: 00101100 //use last 6 bits
Byte 2: 11001101  //use all 8 bits
Byte 3: 01011100 //use all 8 bits
Byte 4: 11100000 //use first 3 bits

Aiming for:
Byte1 + Byte2 = Value 1: 10110011001101 = 11469 in Decimal
&
Byte3 + Byte4 = Value 2: 01011100111 = 743 in Decimal

My code currently looks like this but not sure how to manipulate the bits to get the above format correct?

The byte values returned at the moment are (values should be different to the example above):

PMSB = 10100000
PLSB =  100
TMSB = 1011011
TLSB = 1110100

Code:
 int value 1;
  int value 2;
  byte PMSB;
  byte PLSB;
  byte TMSB;
  byte TLSB;
  Wire.beginTransmission(0x50);
  Wire.endTransmission();
  Wire.requestFrom(0x50,4);
  PMSB = Wire.read();
  PLSB = Wire.read();
  TMSB = Wire.read();
  TLSB = Wire.read();
  value1 = ((PMSB << 8) | PLSB);
  value2 = ((TMSB << 8) | TLSB);


18  Using Arduino / Programming Questions / Re: Date/Time for RTC as seconds since 1/1/2000 on: December 10, 2013, 04:12:32 pm
Well I think your right, hacking the Library like this will trip me up in the future - I would prefer to set those register bits from the sketch but really not sure how to do that?
19  Using Arduino / Programming Questions / Re: Date/Time for RTC as seconds since 1/1/2000 on: December 10, 2013, 03:55:20 pm
Hi Crossroads,

Thanks, I will look at that.  Also, looking at the datasheets it looks as if there are some alarm modes which are not implemented in the Library such as 'When Minutes Match' & 'When Minutes and Seconds Match' - this would suffice as I could just increment minutes and seconds and not worry about what happens to hours, day, months etc - So if I understand right I have modified bit 7 in the registers below to enable 'When Minutes and Seconds Match' - might be a bit of a rough code edit but it could work :-)

Code:
//Enable HH/MM/SS interrupt on /INTA pin. All interrupts works like single-shot counter
void DS3231::enableInterrupts(uint8_t hh24, uint8_t mm, uint8_t ss)
{
    unsigned char ctReg=0;
    ctReg |= 0b00011101;
    writeRegister(DS3231_CONTROL_REG, ctReg);     //CONTROL Register Address

    writeRegister(DS3231_AL1SEC_REG,  0b00000000 | bin2bcd(ss) ); //Clr AM1
    writeRegister(DS3231_AL1MIN_REG,  0b00000000 | bin2bcd(mm)); //Clr AM2
    writeRegister(DS3231_AL1HOUR_REG, (0b10000000 | (bin2bcd(hh24) & 0b10111111))); //Clr AM3
    writeRegister(DS3231_AL1WDAY_REG, 0b10000000 ); //set AM4
}
20  Using Arduino / Programming Questions / Date/Time for RTC as seconds since 1/1/2000 on: December 10, 2013, 12:45:26 pm
Hi,

I have been using the nice DS3231 RTC along with this library https://gist.github.com/jeje/2021145

I would like to be able to set the alarm interupt with the number of seconds since 1/1/2000, ie the starting date for this RTC as reported by this function: 
Code:
Serial.print(now.get(),DEC);

The Alarm is currently set by this function which uses hours, minutes and seconds:
Code:
RTC.enableInterrupts(18,4,16)
; //ie 18:04:16

Is there a clever coder out there who may guide me on how to write a function that uses Seconds since 1/1/2000 to set the alarm?  This would very simply allow me to query the current time with
Code:
now.get
and then add a number of seconds and set the alarm - the nice thing about this would be that all the roller-overs of minutes and hours would be taken care of :-)

The
Code:
RTC.enableInterrupts(18,4,0);
code from the library that I would like to change to
Code:
RTC.enableInterrupts(440003968);


Code:
//Enable HH/MM/SS interrupt on /INTA pin. All interrupts works like single-shot counter
void DS3231::enableInterrupts(uint8_t hh24, uint8_t mm, uint8_t ss)
{
unsigned char ctReg=0;
ctReg |= 0b00011101;
writeRegister(DS3231_CONTROL_REG, ctReg); //CONTROL Register Address
 
writeRegister(DS3231_AL1SEC_REG, 0b00000000 | bin2bcd(ss) ); //Clr AM1
writeRegister(DS3231_AL1MIN_REG, 0b00000000 | bin2bcd(mm)); //Clr AM2
writeRegister(DS3231_AL1HOUR_REG, (0b00000000 | (bin2bcd(hh24) & 0b10111111))); //Clr AM3
writeRegister(DS3231_AL1WDAY_REG, 0b10000000 ); //set AM4
}

21  Using Arduino / Sensors / Re: TSYS01 - function to read temperature...... on: December 02, 2013, 04:46:35 pm
Thanks DC42, much appreciated.

Thanks for pointing out my way too small variable - I really didn't spot that one   smiley-red

Yip, that datasheet needs correcting doesn't it - well spotted, I will email them.  I have my CSB and PS tied as you describe but I'm still not getting good responses - I do get something back which is a start I guess.

I will keep plugging away and post back some code here when I get this working - cheers.
22  Development / Other Hardware Development / Re: New ATTiny Part (ATTiny841) on: November 28, 2013, 05:53:18 pm
Yip, this new MCU looks great, Arduino could do with a nice low-power option for battery powered applications - I will keep watching with interest.  I have used Tindie from the UK before so count me in for a nice 841 low power board :-)
23  Using Arduino / Sensors / Re: TSYS01 - function to read temperature...... on: November 28, 2013, 02:35:38 pm
Still chipping away at this :-)

I'm now wondering if this is something to do with Arduino WIRE using 7 bits and this device using 8 bits - could this be the issue, can I still use this sensor with the Arduino WIRE library and if so how ?

This is what the byte structure looks like:


Cheers
24  Development / Other Hardware Development / Re: New ATTiny Part (ATTiny841) on: November 28, 2013, 09:10:11 am
Hi, will this new MCU be supported by the Arduino IDE?  Thanks.
25  Using Arduino / Sensors / Re: TSYS01 - function to read temperature...... on: November 23, 2013, 07:52:01 am
Getting a bit closer - this code makes much more sense and delivers a result but it is the same result each time round the loop regardless of temperature?

Code:
#include <Wire.h>
#define TSYS01Address 0x77
#define TSYS01Reset 0x1E
#define TSYS01StartReg 0x48
#define TSYS01TempReg 0x00
long tempReading = 0;
float finalTempC = 0.0000;
byte MSB;
byte OSB;
byte LSB;

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

void loop() {
  delay(100);
  TSYS01GetTemp();
  finalTempC = (tempReading/128.0);
  Serial.print("Temperature: ");
  Serial.print(finalTempC);
  Serial.print((char)176); // Degree symbol.
  Serial.println('C');
  Serial.print("MSB: ");
  Serial.println(MSB);
  Serial.print("OSB: ");
  Serial.println(OSB);
  Serial.print("LSB: ");
  Serial.println(LSB);
  Serial.println("-------------------------");
  Serial.println(" ");
  delay(5000);
}

void TSYS01INIT() {
  Wire.beginTransmission(TSYS01Address);
  Wire.write(0x1E);
  Wire.endTransmission();
}

void TSYS01GetTemp()
{
  Wire.beginTransmission(TSYS01Address);
  Wire.write(TSYS01StartReg);
  Wire.endTransmission();
  delay(100);

  Wire.beginTransmission(TSYS01Address);
  Wire.write(TSYS01TempReg);
  Wire.endTransmission();
 
  Wire.requestFrom(TSYS01Address,3);
  MSB = Wire.read();
  OSB = Wire.read();
  LSB = Wire.read();

  tempReading = ((MSB << 16) | (OSB << 8) | LSB);
}
26  Using Arduino / Sensors / Re: TSYS01 - function to read temperature...... on: November 22, 2013, 03:40:53 pm
..... I'm attempting to get this going with the little knowledge I have...... so far my code looks like this clearly there are some big mistakes on my part  smiley-red  At this stage I just hoping to start the conversion and then read the ADC result - once I can get a result I can work on converting this to a temperature.

Code:
#include <Wire.h>
#define address 0x77
int temperature;
const int data_bytes = 7;
byte result_buffer [data_bytes];


void setup()
{
  Serial.begin(9600);
  Wire.begin();
  Serial.println("TSYS01 Test");
}

void loop()
{   
    Serial.println("");
    ReadTSYS01();
    Serial.println("----------------");
    delay(1000);
}

int ReadTSYS01()
{
  Serial.println("Read TSYS01");
  Wire.beginTransmission(address);
  Wire.write(0x48);
  Wire.endTransmission();
 
  Wire.beginTransmission(address);
  Wire.write(0x00);
  Wire.endTransmission();
  Wire.requestFrom(address, data_bytes);

  while (!Wire.available ());
  for (int i = 0; i < data_bytes; ++i)
  {result_buffer [i] = Wire.read();}
 
  for (int i=0;i<7;i++)
  {
   byte d = result_buffer [i];
   if (i==1) temperature = d;
   if (i==2) temperature = (temperature << 8) | d;
  }
 
  Serial.print("Result: ");
  Serial.println(temperature);
 
}
27  Using Arduino / Sensors / TSYS01 - function to read temperature...... on: November 22, 2013, 02:34:03 pm
Hi all,

I have finally managed to solder my TSYS01 high accuracy temperature sensor to a PCB and now I am looking to write a function to read the 24bit temperature value via I2C but the example looks pretty daunting to my eyes.... wondering if anyone can point me in the right direction on how to do this in Arduino speak?  http://meas-spec.com/downloads/TSYS01_Application_Note.pdf

Any pointers very much appreciated.
28  Topics / Science and Measurement / SODAQ - a nice Arduino Low Power Wireless Data Logging Project on: November 18, 2013, 10:06:27 am
Hi,

First up I will place my cards on the table: I'm not involved with the project.... but I am a backer :-)

Just thought this might be of interest to quite a few people who, like me, use Arduino to collect and send sensor data - nice project which looks like it will have legs :-)

http://www.kickstarter.com/projects/386717175/sodaq-a-lego-like-plug-in-rapid-prototyping-board

Enjoy.
29  Using Arduino / General Electronics / Re: 2N7000 as power swtich ? on: October 10, 2013, 06:07:26 am
Thanks again Nick, I will do some reading and learn a little more about MOSFET MATH so I can fully understand :-)  Cheers.
30  Using Arduino / General Electronics / Re: 2N7000 as power swtich ? on: October 10, 2013, 04:09:34 am
... forgot to ask if I need to change the power switching circuit in any way if my system is 3V3?
Pages: 1 [2] 3 4 ... 19