Dear DAVID Community,

In 2016, DAVID and this forum have been integrated into HP Inc.
This forum has been read-only since then, and will be switched off by the end of 2019.

To everyone who has contributed here, we thank you for all your work and for the constructive, helpful and friendly atmosphere you have created!
Please continue to discuss on the HP Support Forums.

Control the arduino board from Davids setup

Re: Control the arduino board from Davids setup

Postby Bongobat » Wed Mar 09, 2011 9:33 pm

Hi,

Did you put an available COM port in the text field? Something like COM2 or whatever port your arduino is on.

Greg
DealExtreme red line laser, Microsoft Lifecam HD-5000
User avatar
Bongobat
Moderator
 
Posts: 1002
Joined: Mon Apr 02, 2007 10:02 am
Location: Ohio, USA

Re: Control the arduino board from Davids setup

Postby Kitamo » Wed Mar 09, 2011 9:50 pm

yeah its ok now, it should work on my netbook coz I got no errors here and i got opened port COM3 i think coz buttons R useable now but tell me what they send to that COM3 when I press them coz I misunderstood that I think.
I got little code writen very quick and its working from arduino software when I send them from Serial monitor

Code: Select all
void loop()
{
  delay(150);

if (Serial.available() > 0)
  {
    inByte = Serial.read();
    if (inByte == 83) // S received from David
    {
    do_scan();
    }
   if (inByte == 84) // T received from David
    {
    stop_scan();
    } 
   if (inByte == 102) // f received from Utility
    {
    motor.setSpeed(3);  // 10 rpm
    motor.step(3, FORWARD, MICROSTEP);
    delay(100);
    } 
   if (inByte == 114) // r received from Utility
    {
    motor.setSpeed(3);  // 10 rpm
    motor.step(3, BACKWARD, MICROSTEP);
    delay(100);
    }
  }
}


Its a part of test code to move laser up and down
Kitamo
 
Posts: 32
Joined: Sat Jan 29, 2011 2:44 am

Re: Control the arduino board from Davids setup

Postby Bongobat » Wed Mar 09, 2011 10:09 pm

Okay when you press and hold the Laser Up or Laser Down button either f or r will be sent but as soon as you release your mouse button a T is sent so you would write your quick position code something like this:

Code: Select all
if (serial == 'f'){
    digitalWrite(laser, HIGH);
    digitalWrite(dir, HIGH);   
    digitalWrite(motor, HIGH);
    delayMicroseconds(fastspd);                 
    digitalWrite(motor, LOW);   
    delayMicroseconds(fastspd);
  } // Quick positioning Forward
  if (serial == 'r'){
    digitalWrite (laser, HIGH);
    digitalWrite(dir, LOW);   
    digitalWrite(motor, HIGH);
    delayMicroseconds(fastspd);                 
    digitalWrite(motor, LOW);   
    delayMicroseconds(fastspd);
  } //Quick positioning Reverse


Because the arduino is in an infinite loop and since T is not f or r it will stop the laser from moving, You could use any character that is not f or r . Once the motor stops the laser will still be on though and I like leaving the laser on so you can see where the laser rests after moving it To turn the laser off before a scan I simply audition the scan because in my code the laser will go off on rewind.

I am probably not the best one to follow on how to code I can be a bit eccentric in my ideas I think :oops:

Greg
DealExtreme red line laser, Microsoft Lifecam HD-5000
User avatar
Bongobat
Moderator
 
Posts: 1002
Joined: Mon Apr 02, 2007 10:02 am
Location: Ohio, USA

Re: Control the arduino board from Davids setup

Postby Bongobat » Wed Mar 09, 2011 10:15 pm

HI,

I wrote my last post before I read yours.

Are you using the adafruit motorshield? I don't have experience with it or it's commands sorry, what I just posted was for a board like the pololu A4983 or the easydriver where you just pulse the step pin.

Greg
DealExtreme red line laser, Microsoft Lifecam HD-5000
User avatar
Bongobat
Moderator
 
Posts: 1002
Joined: Mon Apr 02, 2007 10:02 am
Location: Ohio, USA

Re: Control the arduino board from Davids setup

Postby Kitamo » Wed Mar 09, 2011 10:19 pm

I think it wont work coz that Uttility dont send anything to ports (COM3) on my computer where I got arduino.
I try everything and nothing :/

Yes I got Arduino UNO + adafruit motorshield but its not important, i just need code like your to learn just topology of a source code and its Your code is clear for me, i can reorganize it to any programming language :)

Anyway I know how to start and mby soon I will try to make my own program to controll that :) For now I will use serial monitor from arduino to control my laser position

Your help is awesome coz now I know how to start and for what I should look now :)



EDIT : on what BAUD rate Your program work ?? its defined in that uttility somewhere ?
Kitamo
 
Posts: 32
Joined: Sat Jan 29, 2011 2:44 am

Re: Control the arduino board from Davids setup

Postby Bongobat » Wed Mar 09, 2011 10:30 pm

Kitamo wrote:I think it wont work coz that Uttility dont send anything to ports (COM3) on my computer where I got arduino.
I try everything and nothing :/


To see if it's working you could try just the simplest program turning on the LED if it receives a f or r. You could set up a null modem emulator like com0com connect the output of my program to the input of some terminal program and see if the characters are sent. I thought I read somewhere about com sniffers that let you see what is being transmitted too but I've never used one.

Works on my computer though I recently used it to set up the scan of my head.

EDIT. You do have to put in a number for speed for it to send anything on the scan button, this was to prevent user from starting a scan with no delay on my new microcontroller.

Greg
DealExtreme red line laser, Microsoft Lifecam HD-5000
User avatar
Bongobat
Moderator
 
Posts: 1002
Joined: Mon Apr 02, 2007 10:02 am
Location: Ohio, USA

Re: Control the arduino board from Davids setup

Postby Bongobat » Thu Mar 10, 2011 12:14 am

Hi,

Yes I was thinking maybe it was the baude. It's set at 9600

Greg
DealExtreme red line laser, Microsoft Lifecam HD-5000
User avatar
Bongobat
Moderator
 
Posts: 1002
Joined: Mon Apr 02, 2007 10:02 am
Location: Ohio, USA

Re: Control the arduino board from Davids setup

Postby milz » Thu Mar 10, 2011 3:25 am

hi kitamo

in this thread are some infos about my setup
viewtopic.php?f=9&t=1968&hilit=unlimted&start=30#p13604
i use the arduino + adafruit motorshield
the code are very complex and 2-3 bugs in this version -))

i will update my debug verson asap

mfg milz
Xeon x5650@4ghz
Cam : USB2 CCD 1024x768 / USB3 1280x900
Laser : LC532-5-3-F(16x65) Focusable Green
Projector Acer X110P / Acer K132
dControl one David control box + Turntable + automatic texture lights
mooooom bathroom!!!!!!
User avatar
milz
 
Posts: 520
Joined: Wed Jul 15, 2009 12:24 pm
Location: Germany Cologne

Re: Control the arduino board from Davids setup

Postby Kitamo » Thu Mar 10, 2011 9:52 am

Hi.

I was reading that thread too :)

My mainor problem now is to set good loop in my arduino to run stepper, coz dunno how it should be good constructed.

i got something simple :

void loop()
{

if (Serial.available() > 0)
{
inByte = Serial.read();
if (inByte == 83) // S received from David
{
motor.setSpeed(3); // 10 rpm
motor.step(1, FORWARD, MICROSTEP);
}

}

So this code will
1. read com port and put readed character in inByte
2. if inByte get S character make parameter > run stepper by 1 step forward.
3.Back to beginning and read Com port again.

Ok this code will move my stepper each time when I set S character as entry on my arduino. But I need that to do over and over so i was thinking to set that as AnalyzeImage coz that option in David return over and over (on each frame) specifed character on com port.
And its ok, its working in that way, but even after David stops and stop printing S character as output, my stepper is still working and that command "if ...." is repeating. I think i uderstood wrong that "if" command or Serial.read().

I was trying to do this in other way - to wait my program to get S character as Scan Start and keep that state until on serial port my program will read T command.
So i was trying use "if" condition command as before and put inside another condition wich will wait for T command and thats my problem. I was trying to do this in many ways and its not working as I want. For sure I made some simple logical mistake. To run normal DC motor its simple for me but stepper need need all the time information about how many steps he should move.

I dont know if I write it clear (my english is poor :/) i hope You understand what my problem is. I just wanna my stepper run as long as arduino get character from AnalyzeImage command, or run over and over and check if there is new character on COM port (if recive T command just jump outside from that loop to other place in my code.

I dont understand why my steper wont get to stop, mayby i should use motor.step(relase) at end of loop(i'm in work now and i can't check that).
Kitamo
 
Posts: 32
Joined: Sat Jan 29, 2011 2:44 am

Re: Control the arduino board from Davids setup

Postby Kitamo » Thu Mar 10, 2011 7:48 pm

Hi again.

Here I got full working code
Code: Select all
// Version 1.0.01 Demo
int inByte;  // message from DLS
char outByte ;
#include <AFMotor.h>
AF_Stepper motor(18, 2);
int counter;

void setup() {
  Serial.begin(115200);
  counter = 0;
}

void loop()
{


 
if (Serial.available() > 0)
  {
    inByte = Serial.read();
  }
    if (inByte == 'S') // S received from David
    {
     motor.setSpeed(1);
     motor.step(1, FORWARD, MICROSTEP);
     counter = counter + 2;
    }
    if (inByte == 'T') // T received from David
    {
     motor.setSpeed(4);
     motor.step(counter, BACKWARD, MICROSTEP);
     counter = 0;
    }
   
   
     if (inByte == 'u') // Up received from David
    {
     motor.setSpeed(14);
     motor.step(10, BACKWARD, MICROSTEP);
    }
     if (inByte == 'd') // down received from David
    {
     motor.setSpeed(14);
     motor.step(10, FORWARD, MICROSTEP);
    }

     
}

I made litle mistake when i got first "if" condition wich should check if something is sended to COM port (Serial.read(); ) after that i should set "}" and close condition and all rest of code should be in main loop.

This is very basic and simple code but enough for me for now -

When I press start on David laser start moving down with and "counter" remember how many steps it was down.
When scaner line is out of camera viev, David send T command and stop scanning. laser will get that command too and move backward with double speed and set to start possition.
If i wanna adjust position of a laser, i need to set "u" or "d" to position it on place and put "T" when i wanna stop it.

now i need a simple GUI interface and thats all :)

Thx all for awesome help here :) Now i'm feel more like fish in a water :D after many attemps and fail its my first succes :D hehe :)
Kitamo
 
Posts: 32
Joined: Sat Jan 29, 2011 2:44 am

Previous

Return to Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

cron