Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Wiring Hardware >> Tangible computing >> Wiring + step by step engine
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1259259241

Message started by Florian SIGMA6 on 11/26/09 at 18:14:01

Title: Wiring + step by step engine
Post by Florian SIGMA6 on 11/26/09 at 18:14:01
Hi everyone, so here it is.
I'm using the stepper library to control a step by step engine. (http://www.eminebea.com/content/html/en/motor_list/pm_motor/pg15s020.shtml)

Until here, no problem. This engine as 1000 steps, and i would like to return to processing the actual step of the engine, so i use a serial. It works but processing is missing a lot of data, and wiring keeps messing up a bit.

Here is my wiring code:

Code:
#include <Stepper.h>

int steps = 1000;

char val;
int pas;


Stepper stepper(steps, 0, 1, 2, 3);

void setup(){

  pas = 0;
 
  Serial.begin(9600); 
 
  pinMode(48, OUTPUT);        //Wiring led pin 48.
  digitalWrite(48, HIGH);
}

void loop(){
  if( Serial.available() ) val = Serial.read();
 
  if(val == 'Q'){
    stepper.step(1);
    if (pas == 999) pas = 0;
    else pas++;
   
    Serial.print(pas);
    val = 'x';
  }
  if(val == 'q'){
    stepper.step(-1);
    if (pas == 0) pas = 999;
    else pas--;
   
    Serial.print(pas);
    val = 'x';
  }
 
  if(val == 'W'){
    stepper.step(1);
    if (pas == 999) pas = 0;
    else pas++;
   
    Serial.print(1);
  }
  if(val == 'w'){
    stepper.step(-1);
    if (pas == 0) pas = 999;
    else pas--;
   
    Serial.print(1);
    Serial.flush();
  } 

  delay(100);
}


And here is the processing applet:


Code:
// Built by Florian | SIGMA6 to work with stepper05 in Wiring 0021

//____________________SETUP____________________
//
boolean  debug = false;
//
//_____________________________________________

import processing.net.*;
import processing.serial.*;

// Configuration serial port
Serial port1;




int pas;
byte zero = 0;

void setup() {
  size(200,150);
  background(125);
  frameRate(200);

 
  //--------------------------------------- Déclaration des ports série
  if (!debug) println(Serial.list());
  if (!debug) port1 = new Serial(this, Serial.list()[0], 9600); //Port wiring
 

}

void draw(){}

void serialEvent(Serial port1) {

  pas = port1.read();
  println("test -------- "+pas);*/
  port1.clear();
 
 
}


The idea is that processing is controlling the engine, but he need to know the position (step) of the engine.
For know it's working, but processing gets only half of the steps.

Here is a video to get the idea.
http://www.sigma6.ch/nightly/2009/11/360-degres-projection-test/

And here is an example of some things we managed to do with this version, but could be a lot more precise

Thanks for reading until here.  :P
 


Title: Re: Wiring + step by step engine
Post by barragan on 11/26/09 at 19:03:00
hi there, which Wiring version and OS are you using?

Title: Re: Wiring + step by step engine
Post by Florian SIGMA6 on 11/30/09 at 08:30:54
Hi, i'm using Wiring 0021 and OSX 10.5.8

Title: Re: Wiring + step by step engine
Post by barragan on 11/30/09 at 16:07:23
could you please try with 0022? also try increasing the serial speed.

Title: Re: Wiring + step by step engine
Post by Florian SIGMA6 on 12/01/09 at 16:12:08
Ok, so i tried with 0022 and a higher baudrate (115200)

But i'm still having a lot of data lost.

Code:
#include <Stepper.h>

int steps = 1000;

char val;
int pas;

Stepper stepper(steps, 0, 1, 2, 3);

void setup(){

  pas = 0;
 
  Serial.begin(115200); 
 
  pinMode(48, OUTPUT);        //Wiring led pin 48.
  digitalWrite(48, HIGH);
}

void loop(){
  if( Serial.available() ) val = Serial.read();
 
  if(val == 'W'){
    stepper.step(1);
    if (pas == 999) pas = 0;
    else pas++;
   
    Serial.print(1,BIN);
  }
  if(val == 'w'){
    stepper.step(-1);
    if (pas == 0) pas = 999;
    else pas--;
   
    Serial.print(0,BIN);
    //Serial.flush();
  } 

}



Code:
// Built by Florian | SIGMA6 to work with stepper05 in Wiring 0022

//____________________SETUP____________________
//
boolean  debug = false;
//
//_____________________________________________

import processing.net.*;
import processing.serial.*;


Serial port1;

int pas;
byte zero = 0;

void setup() {
  size(200,150);
  background(125);
  frameRate(600);

 

  if (!debug) println(Serial.list());
  if (!debug) port1 = new Serial(this, Serial.list()[0], 115200); //Port wiring
 
}

void draw(){}

void serialEvent(Serial port1) {
  pas = port1.read();
  if(pas == 48)println("0");
  else println("1");
  //port1.clear();
 
 
}


Title: Re: Wiring + step by step engine
Post by Florian SIGMA6 on 12/01/09 at 16:49:23
Ok here is a very good exemple of my probleme.
I added a delay(500) in the wiring code, and wiring still can get to send all the data to processing...

Wiring:

Code:
#include <Stepper.h>

int steps = 1000;

char val;

Stepper stepper(steps, 0, 1, 2, 3);

void setup(){


  Serial.begin(115200); 
 
  pinMode(48, OUTPUT);        //Wiring led pin 48.
  digitalWrite(48, HIGH);
}

void loop(){
  if( Serial.available() ) val = Serial.read();
 
  if(val == 'W'){
    stepper.step(1);
    Serial.print(1,BIN);
  }
  if(val == 'w'){
    stepper.step(-1);
    Serial.print(0,BIN);
  } 
  delay(500);
}


Processing:


Code:
// Built by Florian | SIGMA6 to work with stepper05 in Wiring 0022

//____________________SETUP____________________
//
boolean  debug = false;
//
//_____________________________________________

import processing.net.*;
import processing.serial.*;

// Configuration serial port
Serial port1;

int pas;
byte zero = 0;

void setup() {
  size(200,150);
  background(125);
  frameRate(3000);

 
  //--------------------------------------- Déclaration des ports série
  if (!debug) println(Serial.list());
  if (!debug) port1 = new Serial(this, Serial.list()[0], 115200); //Port wiring
 

}

void draw(){}


void serialEvent(Serial port1) {
  //pas++;

  pas = port1.read();
  port1.clear(); 
  //println("test -------- "+pas);
  if(pas == 48)println("0");
  else println("1");
  //port1.clear();
 
 
}


Help   :-/

Title: Re: Wiring + step by step engine
Post by barragan on 12/01/09 at 17:29:21
hi Florian, please try this release candidate for your issue:
http://wiring.org.co/download/prerelease/wiring-0023.dmg

Remove the delay(500), it is too big perhaps just 50 or 100 would be fine, also from the code in Wiring I see you are always moving the stepper with the "val" value, perhaps you might want to move it only when you get data? (just checking)

void loop(){
  if( Serial.available() ) {
    val = Serial.read();
 
    if(val == 'W'){
      stepper.step(1);
      Serial.print(1,BIN);
    }
    if(val == 'w'){
      stepper.step(-1);
      Serial.print(0,BIN);
    } 
  }
  delay(500);
}

Title: Re: Wiring + step by step engine
Post by Florian SIGMA6 on 12/01/09 at 18:00:23
First of all thanks for your help. But in fact i expecting the wiring board to keep on looping event if no new serial was sent. But any way i tried your way with the new realase but it keep missing data. I just can't understand why.
Try to use these code, see what you get, but i miss 3 out of 4, more less:
Wiring:
#include <Stepper.h>

int steps = 1000;

char val;

Stepper stepper(steps, 0, 1, 2, 3);

void setup(){


  Serial.begin(115200); 
 
  pinMode(48, OUTPUT);        //Wiring led pin 48.
  digitalWrite(48, HIGH);
}

void loop(){
  if( Serial.available() ){
    val = Serial.read();
 
    if(val == 'W'){
      stepper.step(1);
      Serial.print(1,BIN);
    }
    if(val == 'w'){
      stepper.step(-1);
      Serial.print(0,BIN);
    } 
  }
  delay(100);
}

Processing:
// Built by Florian | SIGMA6 to work with stepper05 in Wiring 0022

//____________________SETUP____________________
//
boolean  debug = false;
//
//_____________________________________________

import processing.net.*;
import processing.serial.*;

// Configuration serial port
Serial port1;

int pas;
byte zero = 0;

void setup() {
  size(200,150);
  background(125);
  frameRate(3000);

 
  //--------------------------------------- Déclaration des ports série
  if (!debug) println(Serial.list());
  if (!debug) port1 = new Serial(this, Serial.list()[0], 115200); //Port wiring
 

}

void draw(){}


void serialEvent(Serial port1) {

  pas = port1.read();
  port1.clear(); 
  if(pas == 48)println("0");
  else println("1");
 
 
}

Title: Re: Wiring + step by step engine
Post by barragan on 12/01/09 at 19:18:54
hi Florian, how are you measuring you are losing data?

Title: Re: Wiring + step by step engine
Post by Florian SIGMA6 on 12/02/09 at 12:36:09
Well, when i use Serial.print(1,BIN) in Wiring, i see in the console every time that Wiring is sending a message to processing, but then in processing, i ask a print on each serialEvent(Serial port1). And i see that processing is not getting all the serials that are printed in Wiring.

Title: Re: Wiring + step by step engine
Post by barragan on 12/02/09 at 15:35:52
ok, now i get it, you are losing data because you are opening the serial port with two apps at the same time, (Processing and Wiring), in PCs this can´t be done at all, but in macs the serial doesn´t complain at all. When reading the serial make sure only ine application is doing it, close the serial monitor in Wiring of you plan to receive data in Processing, or stop the Processing app if you want to use the Serial monitor.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.