Show Posts
Pages: [1] 2 3 ... 19
1  Using Arduino / Motors, Mechanics, and Power / Re: Steppermotor and serial.print and read combined on: Today at 11:22:42 am
oohps forgot the Serial.begin(9600); to add to the setup.
Now we have serial data out but again the stepper motor slows down.

Paco
2  Using Arduino / Motors, Mechanics, and Power / Re: Steppermotor and serial.print and read combined on: Today at 10:50:11 am
OK appolgies for the info.

If I uncomment the line with serial print the stepper motor runs in a very very low speed.

The reason I did not used the accelstepper lib was that I used a piece of sample code that was not refering to it.
So now I for test used this piece of code and added the serial.print in this demo just to see if it keeps the stepper motor speed and a serial value is written. It keeps the speed but serial.print doesnt show anything happening in the serial monitor.

Enable is used on the easy driver too de-energize the coils if the stepper motor is in rest position. There is no need to keep them alive as this only heats up the driver IC.

Code:
#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1, 9, 8);

int pos = 900;
int Position = 1000;

void setup()
{  
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(1000);
}

void loop()
{
  if (stepper.distanceToGo() == 0)
  {
    delay(500);
    pos = -pos;
    stepper.moveTo(pos);
  }
  stepper.run();
  
  Serial.print ("A,");
}

What I need in the end...........
I need to measure a force by a spring on a weigth sensor and the compression in 0.5 mm steps.
Sensor and HX711 IC works fine and with serial.print I send the raw value to the PC.
All other weight calculation and calibration is done in the PC.
I compress the spring step by step and need to measure the force that belong to it.
The coil spring is for example 70 mm long. So I need to compress it to 35 mm. No need to compress it more.
I start a measurement sequence.
Pulse is send from PC to arduino. The rest of the sequence need to be done in the Arduino UNO.
Reset the force value to zero in PC is done too.
The pulse gives the stepper motor the action to start rotate downwards.
As soon as the PC sens a force larger (>) then 1 gram we reset the force and reset the counter of the stepper motor and start to write the data to a file in the PC. So each certain compression value gets it force value. So each 0.5 mm step has a force value.
As soon as the 35 mm is reached the motor rewinds upwards and decompress the spring untill it is 2mm above the point where the measurement of the force started.
We repeat the same sequence and after 5 in row we stop and show the dat in a graph and tabellist.
During the compression the data is shown in a graph too.

I had it all working fine but that was with a H bridge stepper using the L298 IC.
But for easier use I like to use the easy stepper driver but ran in the problem of the serial.print problem,

I hope my intentions with this project are clear if not shoot the questions to me. :-)
3  Using Arduino / Motors, Mechanics, and Power / Steppermotor and serial.print and read combined on: Today at 04:09:52 am
Curious what I do wrong.

Button currrently controls up and down movement of the stepper motor.
Code works but as soon as I uncomment a line related to serial.print it also stops to work correctly.

I need the combination as I use the stepper to compress a spring and measure the force and the current position which need to be send to a PC application.

Am I asking to much from this combo?

Paco

Code:
#include <HX711.h>

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0

HX711 scale(A1, A0); //load cell libary


int Analog2 = 16;           // Use analog port on shield for push button to control movement and Direction
int Analog3 = 17;           // Use analog port on shield for push button to control movement and Direction
int Distance = 0;           // Record the number of steps the motor has done
int delayTimeUp = 300;
int delayTimeDown = 100;
int Position = 1000;
boolean MotorStopDown = 0;
boolean MotorStopUp = 0;
boolean flagStartInit = 0;
boolean flagRecording = 0;
boolean flagReturn = 0;
const int DirPin = 8;
const int StepPin =9;
const int EnablePin = 10;
int IncomingData = 0;
int outByte = 0;
int cmdTemp = 0;
int MaxTravel = 0;
boolean LeftTurn = 0;
boolean RightTurn = 0;

void setup()
{
  pinMode(DirPin, OUTPUT);
  pinMode(StepPin, OUTPUT);
  pinMode(EnablePin, OUTPUT);
  pinMode(Analog2,INPUT);   // set the A2 pin to input
  pinMode(Analog3,INPUT);   // set the A3 pin to input
  digitalWrite(DirPin, LOW);
  digitalWrite(StepPin, LOW);
  digitalWrite(EnablePin, HIGH);
  Serial.begin(9600);
}

void loop()
{  
  
  LeftTurn = digitalRead(Analog2);
  RightTurn = digitalRead(Analog3);  

  if (LeftTurn == 1)  // upwards
  {
    digitalWrite(EnablePin, LOW);
    digitalWrite(DirPin, LOW);
    digitalWrite(StepPin, HIGH);
    delayMicroseconds(delayTimeUp);          
    digitalWrite(StepPin, LOW);
    delayMicroseconds(delayTimeUp);
    digitalWrite(EnablePin, HIGH);
    digitalWrite(DirPin, LOW);
    Distance = Distance + 1;   // record this Step as part of a rotation where 900 is a quarter rotation
    if (Distance == 900);
    {
      digitalWrite(EnablePin, HIGH);
      digitalWrite(DirPin, LOW);
      Distance = 0;   // reset the Motorstep counter to 0
      Position = Position - 1;
    }
  }
  else if (RightTurn == 1)  // downwards
  {
    digitalWrite(EnablePin, LOW);
    digitalWrite(DirPin, HIGH);
    digitalWrite(StepPin, HIGH);
    delayMicroseconds(delayTimeDown);          
    digitalWrite(StepPin, LOW);
    delayMicroseconds(delayTimeDown);
    digitalWrite(EnablePin, HIGH);
    digitalWrite(DirPin, LOW);
    Distance = Distance + 1;   // record this Step as part of a rotation where 900 is a quarter rotation
    if (Distance == 900);
    {
      digitalWrite(EnablePin, HIGH);
      digitalWrite(DirPin, LOW);
      Distance = 0;   // reset the Motorstep counter to 0
       Position = Position + 1;
    }
  }
  else
  {
    digitalWrite(EnablePin, HIGH);
    digitalWrite(DirPin, LOW);
  }

  //Serial.print ("A,");
  //Serial.println (Position); // keeps score of the steps done to calulate the movement in 0.5 mm + or -
  //Serial.print ("B,");
  //Serial.println(scale.read()/100); //raw loadcell data devided by 100
}


4  Using Arduino / Sensors / Re: Wheatstone bridge strain gauge and amplifier setup help on: April 22, 2014, 06:35:59 am
http://yetticave.blogspot.nl/2014/01/wheatstone-bridge-with-arduino.html
5  Using Arduino / Project Guidance / Re: HX711 24 bit ADC with four load cells on: April 02, 2014, 04:09:03 pm
Hello Matt,

I also found out that the two channels can not have the same gain setting. smiley-mad
Currently busy with something else but as soon as that is ready this HX711 will be the next step.
I let you know how far I can get.

Paco
6  Using Arduino / Motors, Mechanics, and Power / Re: Ardumoto shield using as stepper driver on: March 30, 2014, 12:35:32 am
Hi Mark,

Rewiring the shield is not possible as the lines to the L298 chip are to small and it will be come a mess or will destroy the board for next projects.
If people say they got it to work I really need to try it too, just for the feeling it CAN work.  :-)
Ohters will have bought the board too and also stopped trying it to use as a stepper board.

I am new to stepper motors and eager to learn even the long way.

I know about the problem to powerless change the wires otherwise the chip will fail.

I looked again into the .cpp and .h file but cant find the way to change the sequence to the stepping as was proposed as the solution.

I also started to build a simple code without the # stepper,h to see if I can get the board to work.
I have now I think the code that can produce one step either left or right but now it comes down to stepping through to the next step.

Code:
boolean LeftTurn = 0;
boolean RightTurn = 0;
int Analog2 = 16; // Use analog port on shield for push button to control movement and direction
int Analog3 = 17; // Use analog port on shield for push button to control movement and direction

int pwm_3  = 3;    //PWM control for coil outputs 1 and 2 is on digital pin 3
int pwm_11 = 11;  //PWM control for coil outputs 3 and 4 is on digital pin 11
int dir_12 = 12;  //direction control for coil current outputs 1 and 2 is on digital pin 12
int dir_13 = 13;  //direction control for coil current outputs 3 and 4 is on digital pin 13

void setup()
{
  Serial.begin(9600);
 
  pinMode(Analog2,INPUT);   // set the A2 pin to input
  pinMode(Analog3,INPUT);   // set the A3 pin to input
  pinMode(pwm_3,  OUTPUT);
  pinMode(pwm_11, OUTPUT);
  pinMode(dir_12, OUTPUT);
  pinMode(dir_13, OUTPUT);
}

void loop()
{
  LeftTurn = digitalRead(Analog2);
  RightTurn = digitalRead(Analog3);
 
if (LeftTurn == 1) // coil A
{
  StepCounter = StepCounter + 1;
  analogWrite(pwm_3, 255); // > activate coil
  digitalWrite(dir_12, HIGH);  // > left flow coil
}
  else if (RightTurn == 1) //coil B
{
  StepCounter = StepCounter - 1;
  analogWrite(pwm_11, 255); // > activate coil
  digitalWrite(dir_13, HIGH);  // > left flow coil
}
  else
{
analogWrite(pwm_3, 0); // > activate coil
digitalWrite(dir_12,LOW);  // > left flow coi
analogWrite(pwm_11, 0); // > activate coil
digitalWrite(dir_13, LOW);  // > left flow coil

}
7  Using Arduino / Motors, Mechanics, and Power / Ardumoto shield using as stepper driver on: March 28, 2014, 02:26:08 pm
Hi guys,

I see mixed answers when it comes to using this shield https://www.sparkfun.com/products/9815 as a stepper driver
I googled inside and outside the forum but did not came to a satisfying answer to use the shield.
According to this link it should work.
https://forum.sparkfun.com/viewtopic.php?f=14&t=32640
But an other forum member there says the step sequence is not correct but only says he changed two lines in the library but not exactly explains what he did where in the cpp or h file.

His words
---------------------------
I get it working! but in a half: the sequence produced by stepper library isn't correct.
Now is doin 3-4-2-1
What I need to correctly move the motor is 3-1-4-2 (so B-A-B'-A').
----------------------------
This is my current code but the motor only humms and not rotate.

Any help to sort this out would be appriciated.

Thanks Paco

Code:
#include <HX711.h>
#include <Stepper.h>

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0

HX711 scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library

const int stepsPerRevolution = 200;  // Stepper has 200 revolutions for CNC motor
Stepper myStepper(stepsPerRevolution, 3,11,12,13); // See reference for ARDUMOTO - it uses pins 3,11,12,13

boolean LeftTurn = 0;
boolean RightTurn = 0;
int incomingByte = 0;   // for incoming serial data
int StepCounter = 5000;
int Analog2 = 16; // Use analog port on shield for button push to control movement and direction
int Analog3 = 17; // Use analog port on shield for button push to control movement and direction
int ledPin = 8; //used for debug purpose only

void setup()
{
  Serial.begin(9600);
 
  pinMode(ledPin, OUTPUT);  //used for debug purpose only
  pinMode(Analog2,INPUT);   // set the A2 pin to input
  pinMode(Analog3,INPUT);   // set the A3 pin to input
 
  myStepper.setSpeed(70);  // set the speed at 70 rpm:
  // 70 is a nice fluid move  60-70 rpm, and a nice slow rotation could be 20
}

void loop()
{
  LeftTurn = digitalRead(Analog2);
  RightTurn = digitalRead(Analog3);
   
  Serial.print ("A,");
  Serial.println (StepCounter); // keeps score of the steps done to calulate the movement in mm + or -
  Serial.print ("B,");
  Serial.println(scale.read()/100); //raw loadcell data devided by 100

 
  if (Serial.available() > 0)
  {
  incomingByte = Serial.read();
    {
    if (incomingByte = 0)
    {
      LeftTurn = 1;
    }
    if (incomingByte = 1)
    {
      RightTurn = 1;
    }
  }
  }

     
if (LeftTurn == 1)
{
  myStepper.step(stepsPerRevolution); // Do a full left turn of 200 steps
  delay(50);
  StepCounter = StepCounter + 1;
  digitalWrite(ledPin, HIGH); //used for debug purpose only
}
  else if (RightTurn == 1)
{
  myStepper.step(stepsPerRevolution * -1); // Do a full right turn of 200 steps
  delay(50);
  StepCounter = StepCounter - 1;
  digitalWrite(ledPin, HIGH); //used for debug purpose only
}
  else
{
digitalWrite(ledPin, LOW); //used for debug purpose only


//  According to sparkfun forum to correctly move the motor correctly is 3-1-4-2 (so B-A-B'-A') for one direction so change standard libary step sequence.

}
The stepper is a 4 wire with two coils of 3,8 ohm with 200 steps where one coil is conencted to 1/2 and the other connected to 3/4
.
8  Using Arduino / Project Guidance / Re: HX711 24 bit ADC with four load cells on: March 17, 2014, 02:58:19 pm
Yep I found that Lib this afternoon too.

Still do not fully understand it all but I ordered two of these babies and when they are in I first gonna check with this lib if I can get it to work on A channel and then see if the B channel can be trapped too into a println function to get the data over to the PC. It looks like all only use the A channel to be captured or am I missing something then?
Then comes the trick to read four channels. One channel at the time..........for now.

All the hardwork will be done like tarre and zeroing in the PC. I only need the raw data (milivolts). Maybe at a later stage I will see if I can adapt with Blue Tooth and an Android app to get the data the same way as on the PC by USB.

First I have to understand what goes on.

Paco



9  Using Arduino / Project Guidance / Re: HX711 24 bit ADC with four load cells on: March 17, 2014, 04:37:42 am
NY,

I studied the datasheet. Table 3 and figure 2 are conflicting where table 3 is correct and figure 2 contains channel B at 64 gain which should be channel A 64 gain.
Understand now that pulses 25,26,27 determen which data is send out from the HX711 and which gain should be used.
But my knowledge at this moment fails to see how I can read the data to the MCU othe rthen the sample codes.
I have no clue if the current available .h and .cpp files are designed to get also the B channel data.
In all samples only one value is displayed
Serial.print(scale.getGram(), 1);
Serial.println(" g");
or do I understand wrong?

Paco

10  Using Arduino / Project Guidance / Re: HX711 24 bit ADC with four load cells on: March 16, 2014, 04:24:30 pm
Ny,

That would mean 8 analog inputs need to be used?

Paco
11  Using Arduino / Project Guidance / Re: HX711 24 bit ADC with four load cells on: March 16, 2014, 03:05:41 pm
Need to measure independ at each corner a value. Wheel pressure on each wheel......... smiley

Paco
12  Using Arduino / Project Guidance / HX711 24 bit ADC with four load cells on: March 16, 2014, 01:35:44 pm
Hi guys,

I found the HX711 and was curious if it could work for one of my projects which currently uses other ADC..
This 24 BIT ADC has 2 differential inputs for 2 load cells.
In the end I need 4 load cells so that means the use of 2 x HX711.
All the code I found is only refering to measuring one load cell on the A- and A+ input instead of two.
The output for communication is fed to the A0 and A1 analog inputs.

Now would it be possible to have two of the HX711 connected to an UNO and read all the load cells to a serial print function.
The data needs to be ported to a PC by USB.
So the second HX711 connected to A2 and A3.

Would the hx711.h libary need to be adapted or can I change the libaries name for example hx711-1 and hx711-2 and both use in the same sketch ?

Any tips or trick if this could work would be appriciated.
Code:
/* sample for digital weight scale of hx711, display with a HD44780 liquid crtstal monitor
 *
 * hardware design: syyyd
 * available at http://syyyd.taobao.com
 *
 * library design: Weihong Guan (@aguegu)
 * http://aguegu.net
 *
 * library host on
 * https://github.com/aguegu/Arduino
 */

// Hx711.DOUT - pin #A1
// Hx711.SCK - pin #A0

#include "hx711.h"

Hx711 scale(A1, A0);

void setup() {

  Serial.begin(9600);

}

void loop() {

  Serial.print(scale.getGram(), 1);
  Serial.println(" g");

  delay(200);
}
13  Using Arduino / Programming Questions / Re: Code slows down with simple led on/off added on: November 05, 2013, 11:39:23 am
I did a test and found this behaviour.

When I do not change the force measurement of the ADC and perform 4 times in a row a quick on/off led activation there is nothing happening. Then after 3 seconds the led will go on/off four times. If I do the same for 10 times the same behaviour appears. So it looks the on/off switching is stored and then perfomed.

Anyone with some advice on this?

Thanks in advance, Paco
14  Using Arduino / Programming Questions / Re: Code slows down with simple led on/off added on: November 04, 2013, 09:12:27 am
I add the manual of the TM7709 in case this might shine more light to it then it already does.

BTW there two lines of code that say " while  >    A==A"

This is the Original undressed code that belongs to the ADC.
I undressed it from parts I did not needed.

As far I understand it is 8 bits and the length of the word is send when all 8 bits are received.
If there is a delay in sending when there is no value change I can not figure out this cause the loop to wait.

Code:
//TM7709 24bit ADC module arduino sketch
//coldtears electronics

//default connection arduino UNO
//DRDY = 11
//ADIO = 12
//SCLK = 13


#define TM7710_DRDY        3         
#define TM7710_ADIO        4         
#define TM7710_ADIO_OUT()  DDRB|=1<<4     
#define TM7710_ADIO_IN()   DDRB&=~(1<<4) 
#define Set_TM7710_SCLK()  PORTB|=1<<5
#define Set_TM7710_ADIO()  PORTB|=1<<4
#define Clr_TM7710_SCLK()  PORTB&=~(1<<5)
#define Clr_TM7710_ADIO()  PORTB&=~(1<<4)

unsigned char x[3];
long Result;
float vref=4.89;

void TM7710_start(void)   
{
    Clr_TM7710_ADIO();
    delayMicroseconds(1);
    Clr_TM7710_SCLK();
    delayMicroseconds(1);
}

void TM7710_stop(void)   
{
    Clr_TM7710_ADIO();
    delayMicroseconds(1);
    Set_TM7710_SCLK();
    delayMicroseconds(1);
    Set_TM7710_ADIO();
    delayMicroseconds(1);
}

void TM7710_write(unsigned char dd)
{
    unsigned char i;

    for(i=8;i>0;i--)
    {
        if(dd&0x80)
            Set_TM7710_ADIO();   
        else
            Clr_TM7710_ADIO();   
       
        delayMicroseconds(1);
        Set_TM7710_SCLK();       
        delayMicroseconds(1);
        Clr_TM7710_SCLK();     
        dd<<=1;                 
    }
}

unsigned char TM7710_read(void)
{
    unsigned char data=0,i;

    for(i=0;i<8;i++)
    {
        Set_TM7710_SCLK();                   
       
        data=data<<1;                                 
        if((PINB&(1<<TM7710_ADIO))==(1<<TM7710_ADIO)) 
        {
          data=data+1;
        }
        delayMicroseconds(1);
        Clr_TM7710_SCLK();
         delayMicroseconds(1);
    }
    return data;
}
void TM7710_Init()
{
   TM7710_ADIO_OUT();
   delay(100);
   TM7710_stop();
   TM7710_start();
   TM7710_write(0xBF);       
   TM7710_write(0x20);      //Gain=128
   //TM7710_write(0x00); //Gain=16
   TM7710_stop();     
}
void setup()
{
DDRB|=1<<5 ;
delay(1000);
Serial.begin(9600);
Serial.println("TM7709 24bit ADC Module");
TM7710_Init();
}
   
void loop()

   while((PINB&(1<<TM7710_DRDY))==(1<<TM7710_DRDY));
   TM7710_start();
   TM7710_write(0x7F);       
   TM7710_ADIO_IN();         
   for(unsigned char j=0;j<3;j++)
   {
   x[j]=TM7710_read();
   }
   TM7710_ADIO_OUT();         
   TM7710_stop();
   Result=x[0];
   Result = Result * 256;
   Result = Result + x[1];
   Result = Result * 256;
   Result = Result + x[2];
   Result = Result - 6912000;
   
   double volt = Result * vref /16 / 6912000;
   printFloat(volt,6);
   Serial.println(" V  ");

}


 void printFloat(float value, int places) {
 // this is used to cast digits
 int digit;
 float tens = 0.1;
 int tenscount = 0;
 int i;
 float tempfloat = value;

 // if value is negative, set tempfloat to the abs value

   // make sure we round properly. this could use pow from
 //<math.h>, but doesn't seem worth the import
 // if this rounding step isn't here, the value  54.321 prints as

 // calculate rounding term d:   0.5/pow(10,places)
 float d = 0.5;
 if (value < 0)
   d *= -1.0;
 // divide by ten for each decimal place
 for (i = 0; i < places; i++)
   d/= 10.0;
 // this small addition, combined with truncation will round our

 tempfloat +=  d;

 if (value < 0)
   tempfloat *= -1.0;
 while ((tens * 10.0) <= tempfloat) {
   tens *= 10.0;
   tenscount += 1;
 }

 // write out the negative if needed
 if (value < 0)
   Serial.print('-');

 if (tenscount == 0)
   Serial.print(0, DEC);

 for (i=0; i< tenscount; i++) {
   digit = (int) (tempfloat/tens);
   Serial.print(digit, DEC);
   tempfloat = tempfloat - ((float)digit * tens);
   tens /= 10.0;
 }

 // if no places after decimal, stop now and return
 if (places <= 0)
   return;

 // otherwise, write the point and continue on
 Serial.print('.');

 for (i = 0; i < places; i++) {
   tempfloat *= 10.0;
   digit = (int) tempfloat;
   Serial.print(digit,DEC);
   // once written, subtract off that digit
   tempfloat = tempfloat - (float) digit;
 }
 
  }

15  Using Arduino / Programming Questions / Re: Code slows down with simple led on/off added on: November 04, 2013, 05:05:39 am
Jack, if I look at it with my knowledge nothing happens as long as the value stays the same, if this cause a delay I do not know. You might be correct this causes the delay. I did not made the code for the ADC and most of it for me it is "adacadabra". I will check this evening what happens if I constant change the value of the force if the led will switch quicker. Let you know.

Thanks, Paco
Pages: [1] 2 3 ... 19