Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Problems with strcpy changing random variables on: July 10, 2013, 07:12:39 pm
You are indeed a genius.

I have been staring at this for so long I couldn't see the error.

I had:

Code:
const    uint8_t cNameBufSize             = 15;   // 15 gives room for 14 characters
         char    cNameBuf[cValBufSize];           // buffer for menu child name

when I should of had

Code:

const    uint8_t cNameBufSize             = 15;   // 15 gives room for 14 characters
         char    cNameBuf[cNameBufSize];           // buffer for menu child name

I thought I was going crazy.

Sorry to waste your time.
2  Using Arduino / Programming Questions / Problems with strcpy changing random variables on: July 10, 2013, 05:01:02 pm
I have the following code

Code:
struct SET {
  // Temp Settings
  uint8_t   minDayTemp;
  uint8_t   maxDayTemp;
  uint8_t   minNightTemp;
  uint8_t   maxNightTemp;
  uint8_t   canopyTemp;   //DHT22 Sensor
} settings

.
.

 char pageName0[] = "Current       ";   // "String 0" etc are strings to store - change to suit.
 char pageName1[] = "Temp          ";
 char pageName2[] = "Humidity      ";
 char pageName3[] = "Soil          ";
 char pageName4[] = "Temp Options  ";
 char pageName5[] = "Soil Options  ";
 char pageName6[] = "Light Options ";
 char pageName7[] = "Set Date/time ";

// Then set up a table to refer to your strings.

 char *pageNames[] = {    // change "string_table" name to suit   
  pageName0,
  pageName1,
  pageName2,
  pageName3,
  pageName4,
  pageName5,
  pageName6,
  pageName7
};

.
.

const    uint8_t cNameBufSize             = 15;   // 15 gives room for 14 characters
         char    cNameBuf[cValBufSize];           // buffer for menu child name
.
.

void    getPageName(uint8_t page) {
  Serial.print("1 settings.minDayTemp =");
  Serial.println(settings.minDayTemp);
  Serial.println();
  strcpy(cNameBuf, pageNames[page]);
  Serial.print("2 settings.minDayTemp =");
  Serial.println(settings.minDayTemp);
  Serial.println();

}

every time I call getPageName the value of settings.minDayTemp changes for some reason.

I put some debug lines in and the value of settings.minDayTemp = 1 before and 116 after the strcpy calling.  How can this be possible??

I am new to c/c++ with a background in php so please be gentle if I've done something stupid.

Thanks
3  Using Arduino / Programming Questions / How best to store structured data on: June 28, 2013, 08:02:52 pm
I am building a page display menu for a project and wanted to store menu data in the following structure:

Code:
struct PAGECHILD {
  char      name[13];
  char      type;           // i/s/c/f/b  value type i.e int, String, char, float or boolean
  int       valueInt;
  char      valueString[13];
  char      valueChar;
  float     valueFloat;
  boolean   valueBool;
  int       valueMin;
  int       valueMax;
};

struct PAGE { 
  char      name[13];
  int       numChildren;
  PAGECHILD children[];
};

PAGE pages[5];

I then populated the menu items like this:

Code:
void setupPages() {

  memcpy(pages[0].name, "Current     ", 13);
  pages[0].numChildren = 0;
  memcpy(pages[1].name, "Temp        ", 13);
  pages[1].numChildren = 0;
  memcpy(pages[2].name, "Humidity    ", 13);
  pages[2].numChildren = 0;
  memcpy(pages[3].name, "Soil        ", 13);
  pages[3].numChildren = 0;
  memcpy(pages[4].name, "Settings    ", 13);
  pages[4].numChildren = 0;
}



This works fine.

but when I add child menu items as below the code compiles but the board crashes

Code:
void setupPages() {

  memcpy(pages[0].name, "Current     ", 13);
  pages[0].numChildren = 0;
  memcpy(pages[1].name, "Temp        ", 13);
  pages[1].numChildren = 0;
  memcpy(pages[2].name, "Humidity    ", 13);
  pages[2].numChildren = 0;
  memcpy(pages[3].name, "Soil        ", 13);
  pages[3].numChildren = 0;
  memcpy(pages[4].name, "Settings    ", 13);
  pages[4].numChildren = 1;
  memcpy(pages[4].children[0].name, "Test        ", 13);
}

The code is on a mega 2560.  On the due I could have two child items but three crashed the board.

Is this a memory issue?

Is there a better way to store the menu items?

Thanks

4  Products / Arduino Due / Re: Amplify DAC output to 0v-12v on: June 04, 2013, 04:45:58 pm
Thanks for your replies.

I will try stimmers idea number 2.

Thanks again.
5  Products / Arduino Due / Amplify DAC output to 0v-12v on: June 03, 2013, 05:11:57 pm
I am trying to use an arduino due to control the following http://www.vellemanprojects.eu/products/view/?id=354314 dc dimmer for an ac fan.

As far as I understand it the dimmer requires a dc input between 0v and 12v to control the ac fan with 0v stopping the fan and 12v for max speed.

I thought about using the DAC output and amplifying the dac output from the due.

Is this the right way to do it and how do I amplify the signal?

A quick search on Google makes me think that I need an op amp circuit to amplify the signal.  Can somebody point me to a suitable circuit for this or suggest a better alternative?

Thanks
6  Products / Arduino Due / Serial Monitor interupt on: January 24, 2013, 04:30:11 pm
I am currently playing with an i2c accelerometer/gyro (MPU6050) to build a balancing robot.

Rather than keep changing variables in the code and then recompiling and uploading I would like some form of interrupt so that when a command is sent via the serial monitor it changes a variable.

I'm not even sure that an interrupt is what I need to be honest.

So for example, the basic program structure is something like this
Code:
void loop() {
 //update sensors
 ......

 //calculate motor speed
 ......

 //run motors

}

There are different sensitivity settings for the MPU6050.  I want to be change the sensitivity of the accelerometer or gyro using the serial monitor.

Can anybody help or suggest a better way.

Thanks?
7  Products / Arduino Due / i2c communication tutorial on: January 20, 2013, 04:53:47 pm
I am a newbie to arduino and c programming

I have just purchased an arduino due and MPU-6050 6-axis accel/gyro sensor.

My background is website development in php but other than that I have no programming knowledge outside of php.  I have got the sensor working using the i2cdevlib and a bit of tinkering with the library.  My problem is that I don't really understand how the library accesses the registers from the i2c communications and I would like to understand how this works.  I have never had to use bytes etc.

I don't want to have to read through the whole learning c from scratch tutorials as I already have a basic grasp of control structures etc.

Can somebody please suggest a good place to start.

Thanks
8  Products / Arduino Due / Re: avr/prgspace error problem on: January 20, 2013, 04:39:02 pm
I had the same problem.

see this post http://arduino.cc/forum/index.php/topic,139378.0.html
9  Products / Arduino Due / Re: MPU-6050 errors reading data on: December 27, 2012, 09:55:05 pm
I found the problem.

The issue was I think that the mpu-6050 board is set to sleep mode by default.  In order to get round this I first of all added the following library for the MPU6050

http://www.i2cdevlib.com/devices/mpu6050#source

Then I had to comment out the
Code:
#include <avr/pgmspace.h>
in MPU6050.h

and then I had to comment out any additional relating to
Code:
useProgMem
in MPU6050.cpp as there is an issue with <avr/pgmspace.h> on the Arduino Due apparently.

Finally, using the example sketch for the library for raw sensor data I added the following code:

Code:
accelgyro.setSleepEnabled(false);

immediately before:

Code:
accelgyro.initialize();

It now works!
10  Products / Arduino Due / Re: MPU-6050 errors reading data on: December 27, 2012, 07:10:43 pm
I have checked and the baud rates are the same.

To make things more puzzling I have also run the I2C scanner sketch and it outputs

I2C Scanner
Scanning...
No I2C devices found

Scanning...
No I2C devices found

Scanning...
No I2C devices found

When reverting back to the earlier sketch for the MPU6050 the output to serial monitor shows an error of 1 when trying to read the sensor.  The error number is the output from:

Code:
Wire.endTransmission(false);

According to the Arduino reference the error codes are as follows:

    0:success
    1:data too long to fit in transmit buffer
    2:received NACK on transmit of address
    3:received NACK on transmit of data
    4:other error

Therefore it looks like this is an issue with transmit buffer, whatever that is?

How do I resolve this or am I going in completely the wrong direction?
11  Products / Arduino Due / MPU-6050 errors reading data on: December 27, 2012, 01:54:58 pm
I am a complete noobie with both arduino and electronics in general.

I have and arduino due and a mpu-6050 breakout board from ebay http://www.ebay.co.uk/itm/1x-MPU-6050-Module-3-Axis-Gyroscope-3-Axis-Accelerometer-Sensor-MPU6050-Arduino-/320995455051?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item4abcd1f04b

I have connected the

3v3 pin to the 3.3v output on arduino
gnd pin to the gnd pin on arduino
scl pin to scl1 pin on arduino
sda pin to sda1 pin on arduino

I have used the following sketch http://playground.arduino.cc//Main/MPU-6050

the serial output is as follows:

InvenSense MPU-6050
June 2012
WHO_AM_I : 0, error = 1
PWR_MGMT_2 : 0, error = 1

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 4200984, 134257412
temperature: 37.259 degrees Celsius
gyro x,y,z : 1, 0, 137590197,

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 1073747994, 525467
temperature: 36.509 degrees Celsius
gyro x,y,z : 1, 0, 137590197,

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 4200984, 134257412
temperature: 37.259 degrees Celsius
gyro x,y,z : 1, 0, 137590197,

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 1073747994, 525467
temperature: 36.509 degrees Celsius
gyro x,y,z : 1, 0, 137590197,


................

I can't figure out why the error is shown as 1 and there is no change in the gyro readings and the accel readings seem to jump back and forth to exactly the same readings.

can anybody please help??

Thanks
Pages: [1]