Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Transferring an Integer under 100 us on: August 21, 2012, 12:12:57 pm
Why do you need 2 unos?. Can't you just read from the SD card and then output the value?


The second arduino is an Arduino Mega with the Adafruit Touchscreen shield.  I don't want anything to interfere with the motor operation to ensure the motor's movements are as accurate as possible.  I can't read from an SD card, decode the value into an integer, calculate a motor delay based on that integer, and then step a stepper motor while maintaining a touchscreen display without affecting the motor timing.

I had considered what you spoke of JoeN (11 line bus), but tomhow mentioned a timing issue and he was right.  I tried setting up a 4 line bus and found it really hard to keep the two boards in sync.  I also need the bus to be bi-directional so I know if the motor struck something, if it was rebooted on its own, if it's even on, or if it's receiving the sent info correctly.  I found it really hard to program something like that in a reasonable amount of time.  I was hoping something similar was out there, but SPI works great.
2  Using Arduino / Project Guidance / Re: Transferring an Integer under 100 us on: August 20, 2012, 10:11:38 am
The integers can go from -800 to +800.

This kind of integers does perfectly fit into two bytes. With a 400kHz I2C you need about 50us to transmit 2 bytes. How do you get to 130us?

Recall that this project has to communicate between two Arduinos, then from the second Arduino to the stepper motors.  With two transimissions of ~50 µs, plus the processing time on the second Arduino, I can see how the total time could exceed 130 µs.

Edit: Typo

Correct.  I also need to figure out which integer to send and to break the integer up, send the integer bytes, and then reassemble the integer.

Turns out SPI was the answer.  I'm getting around ~52 us from start to finish.  It's a bit more complicated to set up a Salve, but well worth the effort.

Thanks to everyone for the input.
3  Using Arduino / Project Guidance / Re: Transferring an Integer under 100 us on: August 17, 2012, 01:56:00 pm
The integers can go from -800 to +800.
I expect to send an integer every 100 ms.  The integer is how many steps the motor must take for the next 100 ms period.  I could break up the integer into a LSB and MSB and send only a byte per step (reassembling the bytes into an integer on the third step), but I am hoping there is a comm protocol fast enough to do it in one shot.
4  Using Arduino / Project Guidance / Re: Transferring an Integer under 100 us on: August 17, 2012, 01:26:02 pm
Thanks pylon!  I assumed the I2C bus was already confirmed to run in Fast mode.  It lowers the time from ~330 us to ~130 us which still isn't enough.  I also found that the Adafruit Touch screen shield does not like I2C set to Fast Mode.

The reason I need this done is to allow the motor to run without any interruption.  I want to feed the motor controller arduino commands and values without interrupting the motor at its fastest speed.  I also want to drop using an array so I'm no longer limited by the memory size on the controller.
5  Using Arduino / Project Guidance / Transferring an Integer under 100 us on: August 17, 2012, 10:56:50 am
Hello All,

I'm working on a project that has two Arduinos: one to drive a stepper motor and another to read a sdCard and figure out how many motor steps are required.  Currently, I have the sd Arduino read the card, convert the file and fill an array with those steps.  The sd card then sends the steps over to the motor controller arduino via I2C and the motor controller runs the array.

I want to make it so I don't require an array anymore.  I want the sd Arduino to feed an integer of motor steps to the motor Arduino during the motor's downtime.  I've calculated the downtime to being no less than ~120 microseconds.

Is there an easy way to do this?
6  Using Arduino / Project Guidance / Re: Commercial Coffee Machine on: October 12, 2011, 03:41:35 pm
I remember someone made a soft drink machine using RFID cards, maybe you can look over what they did and see where to go:

7  Using Arduino / Project Guidance / Arduino Mega requires reset to work on: October 12, 2011, 03:10:05 pm
Hey All!  Been working on Arduinos since March and due to a lot of info on these boards, I have a pretty decent project that's doing well.  I have encountered a snag though.

I have an Arduino Mega working with a motor controller board, a self-made power distribution board, and an Arduino Uno hooked up with a Sparkfun microSD shield.  The Mega uses I2C to talk to the Uno, and the Uno reads the only file on the microSD card, turns it into an array, and feeds the values back to the Mega.  The Mega then uses the array to run a motor in a pattern.

I can get the Uno to talk to another Uno without a hitch.  The Mega in the project works just fine on its own.  Once I connected it to the Mega, I get nothing (not even serial responses).  I push the reset button, wait a few seconds, and then the project works as expected.

It seems weird that I do not get an instant reset response.  Without the microSD shield and Uno connected the Mega runs just fine.  Any suggestions?  What info will you guys need?

I reviewed the device and tried using an older code with the same hardware setup: the device worked fine.  It seems to be a coding issue, so here's the code I have:
//include wire library
#include <Wire.h>

//set SDcard address
const int SDcard = 1;

//variable to note if initialization passed
boolean initPassed = false;

//to calculate incoming encoded ints
byte master_packet[2];[/color]

//breath waveform
//Waveform is the number of steps per instance where Speed is the delay in milliseconds per interval
//Speed cannot be negative
//Negative Steps reverse the direction
int standardWaveform [300];        //the breathing waveform in motor counts
long standardSpeed = 0;            //time in ms per instance
int standardSize = 0;              //sets the array size

const int dirPin = 22; //LOW = CW, HIGH = CCW
const int stepPin = 23; //used to microstep the motor
const int motorPin = 24; //HIGH enables motor, LOW disables motor
const int homePin = 25;         //tells if the motor is at the home position  OPEN == HIGH, CLOSED == LOW

int stepNumber = 0;
int currentStep = 0;
long stepDelay = 0;
int motorPosition = 0;
int addPosition = 1;

void setup(){
        //troubleshooting code
        delay(1000);  //delay 1 second
//disable the motor prior to initializing
pinMode(motorPin, OUTPUT);          //set the motor pin as an output
digitalWrite(motorPin, LOW);        //set the pin's voltage low to disable the motor

//initialise I2C with motor board as master
Wire.begin();  //master has no address

        //run a test read to purge the bad data
        initPassed = testSdCard();
//call funcion to read array and receive arrary size
standardSize = getSdArray(&standardWaveform[0]);
        standardSpeed = standardWaveform[0];
//Serial.print the array to confirm it was received properly
Serial.print("\nArray Aquired!\nSpeed is: ");
        Serial.print("\nBreath Wave size is: ");
for (int i = 1; i < standardSize; i++)

//initializing pins
pinMode(stepPin, OUTPUT);    
pinMode(dirPin, OUTPUT);           
pinMode(homePin, INPUT);           
//move the motor to the start position
digitalWrite(dirPin, LOW); //set direction CW
digitalWrite(motorPin, HIGH); //enable the motor

        //moving motor to the lowest position
while (digitalRead(homePin) == HIGH) {
digitalWrite(stepPin, HIGH);  //step the motor
digitalWrite(stepPin, LOW);   //prepare for another step
delayMicroseconds(400);       //wait in microseconds

  digitalWrite(dirPin, HIGH); //set direction CCW
        for (int x=0; x < 7000; x++){
                digitalWrite(stepPin, HIGH);  //step the motor
digitalWrite(stepPin, LOW);   //prepare for another step
delayMicroseconds(500); //wait in microseconds



When starting the device, it won't even display "Begin!" until I reset it.  I can only guess that this is a Wire I2C issue.
8  Using Arduino / Displays / LCD Driver Issues on: June 24, 2011, 11:48:43 pm
I've been working with an Arduino Uno for a few months and now I have an Embedded Artists’ 3.2 inch QVGA TFT Color LCD Board I'm trying to get working with the Arduino.  Been struggling with it the last week with no progress.

I've read on the forums about the touch LCD screen Arduino shield using the same driver, but I wasn't able to see the pinout for the files.  So I've been trying just to turn the LCD on and writing to the register properly.  At first, I tried it with SPI

Pin settings
SPI Pins
Pin 10 = SS/CS   //slave select or Chip Select
Pin 11 = MOSI    // Master Out Slave In
Pin 12 = MISO    // Master In Slave Out
Pin 13 = SCK     //System Clock, used to sync pulses

Pin 9 = RS // Register Set input: low for Commands and high for GRAM


#include <SPI.h>

const int RS = 9;     //Active low commands or Active high for ram writing
const int CS = 10;    //chip select/slave select for LCD
const int MOSI = 11;  //Master Out Slave In
const int MISO = 12;  // Master In Slave Out
const int SCK  = 13;  //Serial Clock, used to sync pulses
int i = 0;
byte responseOne = 0;
byte responseTwo = 0;

void setup(){
  //initiate SPI pins
  //start shifting with MSB MSB (bit 7, bit 6, etc)
  //samples on rise, idle low
  //set SPI speed to 8 MHz
  //set pin modes
  pinMode(RS, OUTPUT);
  //initialize the LCD
  Serial.println('Initialization complete\n');

void loop(){
  //set the cursor position
  //set pixel color

void WriteToLCD(word address, word value){
  //move to command address
  digitalWrite(RS,LOW);            //instruction to accept ram position
  digitalWrite(CS,LOW);            //activate LCD for serial transmission
  byte temp = highByte(address);  //takes the leftmost byte of 'address'
  responseOne = SPI.transfer(temp);             //sends the value via SPI
  temp = lowByte(address);        //takes the rightmost byte of 'address'
  responseTwo = SPI.transfer(temp);             //sends the value via SPI
  digitalWrite(CS,HIGH);           //deactivate LCD for serial transmission
  Serial.print("Address: ");
  Serial.print(" Response: ");
  Serial.print(" ");
  //enter in command
  digitalWrite(RS,HIGH);   //instruction to enter command
  digitalWrite(CS,LOW);    //activate LCD for serial transmission
  temp = highByte(value); //takes the leftmost byte of 'value'
  responseOne = SPI.transfer(temp);     //sends the value via SPI
  temp = lowByte(value);  //takes the rightmost byte of 'value'
  responseTwo = SPI.transfer(temp);     //sends the value via SPI
  digitalWrite(CS,HIGH);   //deactivate LCD for serial transmission
  Serial.print("           Command: ");
  Serial.print(" Response: ");
  Serial.print(" ");

void LCD_Reset(void)
  WriteToLCD(0x0007, 0x0021);   // Display Control
// D1 0x0000 = display off
// D1 0x0002 = display on
// D0 0x0000 = internal display halt
// D0 0x0001 = internal display operate     
  WriteToLCD(0x0000, 0x0001);   //Start Oscillation OSCEN=1
WriteToLCD(0x0007, 0x0023);   // Display Control   
  WriteToLCD(0x0010, 0x0000);   //Sleep mode cancel
  WriteToLCD(0x0007, 0x0033);   // Display Control   
  WriteToLCD(0x0011, 0x6030);   //Entry Mode
                                    // DFM   0x4000 = 262k color
                                    // DFM   0x6000 = 65k color
                                    // AM    0x0000 = horizontal display
                                    // AM    0x0008 = Vertical display
                                    // ID[0] 0x0000 = horizontal decrement
                                    // ID[0] 0x0010 = horizontal increment
                                    // ID[1] 0x0000 = Vertical decrement
                                    // ID[1] 0x0020 = Vertical increment
  WriteToLCD(0x0002, 0x0000);   //LCD driver AC setting
        WriteToLCD(0x0022, 0x0000);  //write to ram

I couldn't confirm if my registry edits were bad or if my writing to the GRam is faulty.  I moved over trying parallel but I can't even get the LCD to turn on.
Pages: [1]