Show Posts
|
|
Pages: 1 [2] 3 4
|
|
16
|
Using Arduino / Programming Questions / sdin.eof() reading CSV error..
|
on: January 22, 2013, 01:50:02 pm
|
Hello, With my DUE I am recieving encoder positions and writing the to an SD card via .csv. Each entry contains 2 ints and 2 floats with commas and no spaces. Now, I wish to read the created file with the Arduino and just display them through the Serial communication. I am getting an error at: if (!sdin.eof()) error("readFile") It seems like the created file is not ending with an EOF which is triggering this error. The code is large, so I will post the interface between writing and reading. Writingvoid loop() { err = slaveEncoder - masterEncoder; analogWrite(EnA, setPWM(err)); // Write PWM value as the encoder count of the Master (controller) if (recordState == true){ int m; m = millis(); if (m % LOG_INTERVAL == 0) {
// use buffer stream to format line obufstream bout(buf, sizeof(buf)); bout << m << ',' << ID << ',' << masterEncoder << ',' << slaveEncoder << endl; ID++;
#if ECHO_TO_SERIAL cout << buf; #endif // ECHO_TO_SERIAL
// log data and flush to SD logfile << buf << flush; // check for error if (!logfile) error("!!WDF!!"); //Write Data Fail // don't log two points in the same millis if (m == millis()) delay(1); } } if (Serial.available() > 0){ command = Serial.read(); if (command == 82){ //R - Record cout << pstr("Recording...") << endl; recordState = true; return; } else if (command == 84){ //T - Traverse cout << pstr("Stopped...") << endl; logfile.close(); readFile(); recordState = false; return; } else if (command == 83){ //S - Stop cout << pstr("Stopped...") << endl; logfile.close(); recordState = false; return; } else if (command == 88){ //X - Exit logfile.close(); cout << pstr("Done!"); while (1); } else return; } } Readingvoid readFile() { int read_millis; int read_ID; float read_ME, read_SE; char comma1, comma2, comma3; // open input file ifstream sdin(fileName); // check for open error if (!sdin.is_open()) error("open"); // read until input fails while (sdin >> read_millis >> comma1 >> read_ID >> comma2 >> read_ME >> comma3 >> read_SE) { // error in line if not commas if (comma1 != ',' || comma2 != ',' || comma3 != ',') error("comma"); // print in six character wide columns cout << read_millis << setw(6) << read_ID << setw(6) << read_ME << setw(6) << read_SE << endl; } // Error in an input line if file is not at EOF. if (!sdin.eof()) error("readFile"); } If anyone can suggest a reason why I cannot read the file properly, I would really appreciate a tip  Daniel
|
|
|
|
|
17
|
Products / Arduino Due / Re: RTClib DS1307 with Arduino
|
on: January 21, 2013, 12:15:09 pm
|
Hello, With the new library, I am running "ds1307" example in a new .pde file and I am getting the same error as the previous library. test:6: error: expected ')' before '*' token test:6: error: expected ')' before '*' token test.ino: In function 'void setup()': test:11: error: request for member 'begin' in '1074666080u', which is of non-class type 'Rtc*' test:13: error: request for member 'isrunning' in '1074666080u', which is of non-class type 'Rtc*' test:16: error: request for member 'adjust' in '1074666080u', which is of non-class type 'Rtc*' test.ino: In function 'void loop()': test:21: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*'
This seems to be bug, would you know why this is the case? Many poeple on the forums are getting this error. Daniel
|
|
|
|
|
18
|
Products / Arduino Due / RTClib DS1307 with Arduino
|
on: January 18, 2013, 03:21:54 pm
|
Hello, I got the RTClib from ladyada but running it with my code, I am getting the following error. Are people getting this library to work with them? motortestdue:56: error: expected ')' before '*' token motortestdue:56: error: expected ')' before '*' token motortestdue.ino: In function 'void dateTime(uint16_t*, uint16_t*)': motortestdue:60: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*' motortestdue.ino: In function 'void setup()': motortestdue:119: error: request for member 'begin' in '1074666080u', which is of non-class type 'Rtc*' motortestdue:123: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*' motortestdue.ino: In function 'void loop()': motortestdue:234: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*' Or, does anyone else have a good RTC DS library? Dan
|
|
|
|
|
19
|
Products / Arduino Due / Re: SdFat for Due posted
|
on: January 18, 2013, 02:57:45 pm
|
I think I am okay with the speed I have - I am just logging 2 byte numbers at 50Hz - so if I need the extra space, I will change the design. Thanks 
|
|
|
|
|
20
|
Products / Arduino Due / Re: SdFat for Due posted
|
on: January 18, 2013, 12:09:26 pm
|
|
Hmmm, interesting, I changed it to EIGHTH speed and quickstart, benchmark and sdformatter all worked. But that was the only speed that allows me. I hope this is fast enough for my application. How can I try and obtain a faster speed. Perhaps the 6'' cables are too long.
Dan
|
|
|
|
|
22
|
Products / Arduino Due / Re: SdFat for Due posted
|
on: January 17, 2013, 05:27:32 pm
|
I am having trouble getting my card prepped for the DUE, I am using the SanDISK Extreme Pro 16 Gb (95Mbps) Running QuickStartEnter the chip select pin number: 10
Card successfully initialized.
Can't determine the card size. Try another SD card or reduce the SPI bus speed. The current SPI speed is: 10.50 MHz Edit spiSpeed in this sketch to change it.
Running PrintBenchmarkType any character to start Free RAM: 95507 Can't access SD card. Do not reformat. SD errorCode: 0X4,0XFF
Any ideas why this is the case? Dan
|
|
|
|
|
23
|
Products / Arduino Due / Did I damage my board?
|
on: January 16, 2013, 12:30:27 pm
|
|
Hello,
I am trying to communicate between a DUE and an UNO via I2C. I had the communication wire up with a pullup resistor to 5V. For about 5-8 minutes I was trying to debug why the UNO wasnt receiving any information and then I realized that the DUE's tolerance is 3.3V.
Could giving 5V to these pins (SCL1 and SDA1 on the DUE) for about 5-8 minute damage the board? If so, how can I check?
Daniel
|
|
|
|
|
24
|
Products / Arduino Due / Re: DUE PWM Frequency
|
on: January 16, 2013, 11:58:32 am
|
Hello, I have fixed the problem, somewhat. Looking into variant.cpp { PIOB, PIO_PB25B_TIOA0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC0_CHA0 }, // TIOA0 { PIOC, PIO_PC28B_TIOA7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA7 }, // TIOA7 { PIOC, PIO_PC26B_TIOB6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHB6 }, // TIOB6
// 5 { PIOC, PIO_PC25B_TIOA6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM, TC2_CHA6 }, // TIOA6 { PIOC, PIO_PC24B_PWML7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH7, NOT_ON_TIMER }, // PWML7 { PIOC, PIO_PC23B_PWML6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH6, NOT_ON_TIMER }, // PWML6 { PIOC, PIO_PC22B_PWML5, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH5, NOT_ON_TIMER }, // PWML5 { PIOC, PIO_PC21B_PWML4, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), NO_ADC, NO_ADC, PWM_CH4, Notice that only pins 7, 6, 5 and 4 respond to the #define in the variant.h file. I am not sure how to configure the rest of the pins to act accordingly. I havent tried changing NOT_ON_PWM (highlighted in the other pin configurations) to PWM_CH#, if this is possible. I am assuming the architecture allocates pins 2-13 as PWM pins but on 5-7 as reconfigurable PWM pins. If anyone would like to contribute why/how to reconfigure other pins - that would be helpful. Daniel
|
|
|
|
|
25
|
Products / Arduino Due / Re: DUE PWM Frequency
|
on: January 15, 2013, 12:07:24 pm
|
You have to restart the IDE if you make changes to the underlying libraries as they are compiled only once for the sketch "to save time".
you might look at PWMC_ConfigureClocks() Hello, I restarted my IDE to let it recompile, but I am still getting 1KHz PWM frequency, also I put the following line into setup but that did not do anything. PWMC_ConfigureClocks(3922 * PWM_MAX_DUTY_CYCLE , 0, VARIANT_MCK);. I wouldn't prefer either way since this micro is designated for motor control, if anything I would like to strictly change the variable in variant.h - if you know any reason why it is still not change, I would much appreciate it. Daniel
|
|
|
|
|
26
|
Products / Arduino Due / Re: DUE PWM Frequency
|
on: January 10, 2013, 03:52:17 pm
|
|
Has anyone found a solid way (preferably in sketch) to modify the output PWM frequency? Also changing variant.h from 1k to what ever you want isnt working for me. Changing it and saving doesn't change the output frequency.
Daniel
|
|
|
|
|
27
|
Using Arduino / Project Guidance / Oscilating Motor Instability
|
on: January 10, 2013, 03:37:58 pm
|
Hello, I am controlling a motor using a PID controller and a master and slave quadrature encoder on a DUE. When the error between master and slave become greater than 255, my motor cannot read steady states and oscillates. One way I have figured out to solve this is essentially never letting the error go up 255 by incrementing encoder counts by decimals. Doing this makes my control very slow - It will take many revolutions in my master side to complete my slave side. I tried tuning and changing encoder counts.. I am wondering if people have clues and suggestions? /* Project: Name: Daniel G Date: 10/15/2012 Company: RRI */
/* EnA | In1 | In2 | Description ----------------------------------------------- 0 | X | X | Free Running Motor Stop 1 | 1 | 0 | Forward 1 | 0 | 1 | ReverslaveEncoder 1 | 1 | 1 | Fast Motor Stop -----------------------------------------------
CHA: ____EEEE____EEEE____EEEE____EEEE CHB: EE____EEEE____EEEE____EEEE____EE When CHA rislaveEncoders check the state of CHB. From here you can determine the direction of the encoder corresponding to the Master or Slave */
#include <stdio.h>
int In1 = 8; int In2 = 9; int EnA = 10; int Master_CHA = 2; // Interrupt INT0 on Pin 2 0 int Master_CHB = 4; // int Slave_CHA = 3; // Interrupt INT1 on Pin 3 1 int Slave_CHB = 6; //
int Master_CHB_val = 0; int Slave_CHB_val = 0; volatile float masterEncoder = 0; volatile float slaveEncoder = 0;
// Control Signal and Error float u = 0; float err = 0;
// PID Control int Kp = 10; double Ki = .008; double Kd = 0.2;
// Error Variables float err_old = 0; float err_intgrl = 0; float err_dot = 0; int max_int = 255; int max_der = 255;
void setup() { Serial.begin(115200); // slaveEncodertting Motor Pins pinMode(In1, OUTPUT); // Setting In1 (direction indicator) pinMode(In2, OUTPUT); // Setting In2 (direction indicator) pinMode(EnA, OUTPUT); // Setting PWM output // Set Encoder Pins & Interrupt pinMode(Master_CHB, INPUT); pinMode(Slave_CHB, INPUT); attachInterrupt(Master_CHA, Master_checkDirection, RISING); // CHA causes interrupt service routine attachInterrupt(Slave_CHA, Slave_checkDirection, RISING); // CHA causes interrupt service routine // PWMC_ConfigureClocks(4000 * PWM_MAX_DUTY_CYCLE , 0, VARIANT_MCK); // TCCR1B = TCCR1B & 0b11111000 | 0x02; // PWM frequency changed from 500Hz to 3.922KHz - L298 typically can support 25KHz. }
// ISR for Master (Controller) void Master_checkDirection() { Master_CHB_val = digitalRead(Master_CHB); // When CHA RAISES check CHB if (Master_CHB_val == 0) masterEncoder += 0.1; // Increment Master count for a direction else masterEncoder -= 0.1; // Decrement Master count for the other direction }
// ISR for Slave (Motor) void Slave_checkDirection() { Slave_CHB_val = digitalRead(Slave_CHB); // When CHA RAISES check CHB if (Slave_CHB_val == 0) slaveEncoder += 0.1; // Increment Slave count for a direction else slaveEncoder -= 0.1; // Decrement Slave count for the other direction }
// Function to Set Direction of PWM void setDirection(boolean In1_State, boolean In2_State) { digitalWrite(In1, In1_State); digitalWrite(In2, In2_State); }
void loop() { err = slaveEncoder - masterEncoder; err_dot = err - err_old; err_dot = constrain(err_dot, -max_der, max_der);
err_intgrl = err + err_intgrl; err_intgrl = constrain(err_intgrl, -max_int, max_int); u = float(Kp*err + Kd*err_dot + Ki*err_intgrl); u = constrain(u, -255, 255); if (u < 0) {setDirection(LOW, HIGH); u = -u;} else setDirection(HIGH, LOW); analogWrite(EnA, u); // Write PWM value as the encoder count of the Master (controller) err = err_old; Serial.print(masterEncoder); Serial.print("|"); Serial.print(slaveEncoder); Serial.print("|"); Serial.println(u); }
|
|
|
|
|
28
|
Using Arduino / Storage / Re: SD.open Returning 0
|
on: December 10, 2012, 11:17:08 am
|
|
The SD Card works just fine, but I realized that I was using the wrong library. I need to be using SdFat, it is very robust so I hope to understand this quickly, thank you for your help.
Daniel
|
|
|
|
|
30
|
Using Arduino / Storage / Re: SD.open Returning 0
|
on: November 29, 2012, 06:02:47 pm
|
PaulS, sorry about that - I have a poor tendancy leaving it out. #include <Wire.h> #include <I2C_Anything.h> #include <LiquidCrystal.h> #include <SD.h>
int CS_PIN = 10;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const byte MY_ADDRESS = 42;
float REFRESH_RATE = 0.0; long ID = 1;
void setup() { Serial.begin(9600); Wire.begin(MY_ADDRESS); Wire.onReceive(receiveEvent); lcd.begin(16,2); pinMode(CS_PIN, OUTPUT); lcd.setCursor(0,0); lcd.print("ME: "); lcd.setCursor(8,0); lcd.print("SE: "); lcd.setCursor(0,1); lcd.print("Datalog: "); if (!SD.begin(CS_PIN)) { Serial.println("Card Failure"); return; } Serial.println("Card Ready"); }
volatile boolean haveData = false; volatile int X; volatile int Y; int LOOP_COUNTER = 0;
void loop() { if (haveData) { lcd.setCursor(3,0); lcd.print(X); lcd.setCursor(11,0); lcd.print(Y); haveData = false; } File dataFile = SD.open("LOG.csv", FILE_WRITE); if (LOOP_COUNTER == 500) { if (dataFile) <--- always prints 0 { dataFile.print(millis()); dataFile.print(", "); dataFile.print(ID); dataFile.print(", "); dataFile.print(X); dataFile.print(", "); dataFile.println(Y); dataFile.close(); lcd.setCursor(9,1); lcd.print("Success"); ID++; } else { lcd.setCursor(9,1); lcd.print("Failure"); } LOOP_COUNTER = 0; } LOOP_COUNTER++; }
void receiveEvent (int howMany) { if (howMany >= (sizeof X) + (sizeof Y)) { I2C_readAnything (X); I2C_readAnything (Y); haveData = true; } }
|
|
|
|
|