Show Posts
Pages: [1] 2 3 ... 11
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Program a GUI in C/C++ for arduino and mouse cursor control on: August 04, 2012, 12:19:56 am
Shploop,
I googled "serial and c++" and got these links

http://www.codeproject.com/Articles/992/Serial-library-for-C
http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c2503/CSerial--A-C-Class-for-Serial-Communications.htm

It probably addresses some of your concerns.
As for making a cross platform app .. you may get in trouble. It's beyond my reach.
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Firmata on: August 01, 2012, 03:46:33 pm
That makes sense Paul.
3  Using Arduino / Interfacing w/ Software on the Computer / Re: Firmata on: August 01, 2012, 09:48:33 am
Quote
Wouldn't be related to that unconditional delayMicroseconds() on every pass through loop(), would it?

I think that it's too slow to be noticed. To be frank, if I noticed the signal as the turn-on of a led .. it might be the time it takes of lighting it up.

Quote
Why is that there?
Interesting question. I read somewhere that it takes 130 microSeconds to make a proper analog reading. So, I respond by making a delay of that size, to make the reading right. .. like it takes time to read the serial ..
Why on earth the serial.read() does not complete what it's supposed to do and need a delay() is beyond me, but I've seen it so often that I just do it.
4  Using Arduino / Interfacing w/ Software on the Computer / Re: Firmata on: August 01, 2012, 08:22:30 am

I cann't say that I'm particularly experienced, but my first contact with an arduino board was through visual basic and my pc. The pc 'sees' a serial port and writes/reads it. As I understand, Firmata is an intermediary that does the same. But interfacing arduino through the serial is not particularly difficult.

I've later used Firmata.
This is feadback from arduino to processing .. I need fast and furious sensor-feedback from one particular pin, so I cut down one of the firmata sketch examples to this:
Code:
#include <Firmata.h>

byte analogPin = 0;

void analogWriteCallback(byte pin, int value)
{
    if (IS_PIN_PWM(pin)) {
        pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
        analogWrite(PIN_TO_PWM(pin), value);
    }
}

void setup()
{
    Firmata.setFirmwareVersion(0, 1);
    Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
    Firmata.begin(57600);
}

int val ;
int valOld=1 ;
void loop()
{
    while(Firmata.available()) {
        Firmata.processInput();
    }
    val=analogRead(analogPin);
    delayMicroseconds(150) ;
    if( val != valOld ){
      Firmata.sendAnalog(analogPin, val);
    }
    valOld = val ;
}

Even though nothing else happens I'm convinced that I can sense a small delay from the 'ping' from the sensor til the value arrives at processing. If this delay has potential of cocking up anything you intend to do, then make it happen exclusively in the arduino.
5  Using Arduino / Interfacing w/ Software on the Computer / Re: Program a GUI in C/C++ for arduino and mouse cursor control on: July 30, 2012, 03:05:27 am
what about threading? when I have a GUI let's say in C++ and a user is interacting with it while it receives and processes data from the Arduino do I need some kind of threading?
It would probably be more cumbersome than building your application like a loop. The serial events seems to at least have some asynchronicity about it (in/outgoing data stays in buffer until read/written). In the loop you can poll sequentially if something happened on the mouse or in the serial ..
6  Using Arduino / Interfacing w/ Software on the Computer / Re: Using Microsoft Visual Programming Language? on: July 27, 2012, 07:16:15 am
rendeverance,
I've been through the input of the post again. I think that we have complicated a fairly simple matter.
It would be nice if you would refrase 'sequence' though. Event has a solid code-technical meaning.
The sequence you've marked in the

void button1_Click1(GButton button)
// MY SEQUENCE HERE:-

looks like a start button (judged on the logic of it). As such, it should run until you explicitly stop it (or it meats a foul value).
There is problem in the logic though: If we say the value lie in between 10 and 1000, then both cases for ledPin, Arduino.LOW and HIGH are
met. You probably mean something like this:
int res = arduino.analogRead(pin) ;
while(res>10 && res<1000) { .. do stuff..}

If it's a start/stop, then let it set a boolean variable [say onOffBool] to true or false .. and let
arduino.digitalRead(switchPin)==Arduino.HIGH
controle the same variable. Or maybe better to let the every second button-press change
arduino.digitalRead(switchPin) between HIGH and LOW
and test if digitalRead(switchPin) is on/off during ordinary data-display

The appropriate place to test the on/off condition could be in the loop:

  if(!onOffBool) {   // or  if( digitalRead(switchPin)== LOW )
    sch = "OFF";  
  } else {
    sch = "ON";
     // turn other data-reads off
   // do ordinary data display
  }


7  Using Arduino / Interfacing w/ Software on the Computer / Re: walk through Firmata .. on: July 26, 2012, 05:23:12 pm
Quote
That's what Firmata does, so, yes.

Well, it takes time to get to know all components.

Quote
Sending ASCII data is not the way to do it, then. Send binary data - much faster.

I googled around to get a gist on weather I could use usb for the SPI bitbanging. That appears to not be the case.
I need one bit. And I need it now.
Anyway, time rushes on. The project is obsolete.
8  Using Arduino / Interfacing w/ Software on the Computer / Re: Using Microsoft Visual Programming Language? on: July 26, 2012, 10:14:19 am

rendeverance,
Just stay away from delay(..)
Take a look at the button-debounce example for 'the standard way' to execute code after a set time.

as for the while, you may get somewhere by adding a
 break;
statement in each while
9  Using Arduino / Interfacing w/ Software on the Computer / Re: walk through Firmata .. on: July 26, 2012, 01:28:56 am
Hi dxw00d,
I have to say, though, I find it better to write my own sketches on the Arduino and in Processing, and ignore Firmata altogether.
I'm out late on responding, I hope you still are around. The meaning of your line didn't strike me at first ..
Can I assume, that you'll build a way to communicate over the serial? I could do that (I did it from visual basic), but the focus would be to make it sufficiently fast. .. Maybe I should have a look at SPI and see if that can bring me anywhere.
10  Using Arduino / Interfacing w/ Software on the Computer / Re: Using Microsoft Visual Programming Language? on: July 25, 2012, 12:57:41 pm
I need to work on this code business, I will look at your examples and see if I can gleam inspiration. I mean I don't need it blisteringly quick but I need it accurate within 1 second really.
no problem if you'r talking about pure transmission-time
Quote
I think my main issue is getting everything to work together, none of the things I want it to do are particularly complex, its just that I have many things going on at once and I am having trouble tying them together!
You should consider ... a helicopter-view with an intent to stick to broad lines and clarity. By that I mean, that you should consider to segment your code into easily understandable units. That could be by collecting some tasks under a common class. Imo complexity is a problem on it's own.
Quote
Are there any examples specifically applicable to performing a sequence of events (which is feedback dependent) while having an option to pause and / or interrupt the sequence?
Are you talking pc-application? If so, I can suggest that you think circular: Make a loop that contains the tasks and decide exit-points. Control it by boolean variables: In the event-handler you flip a boolean, and it opens/closes the task that is in the loop (behind the bool).
When you use a loop in vb you might utilize a function application.doEvents() once for every loop, to listen for changes. If you look at the blinking-leds or button- examples (arduino), you may see how to build a 'state' on both sides of an event (a button-click changes from state-on to state-off) ... etc. Then, check states in each loop and act upon it.
And, do remember to name your variables right .. that makes understanding that much easier.

... so much from an amateur
11  Using Arduino / Interfacing w/ Software on the Computer / Re: Using Microsoft Visual Programming Language? on: July 25, 2012, 09:38:56 am

rendeverance,
If you think in terms of communication through the usb .. you have all that you need. Make button-presses in your gui send a serial message and write code in arduino to 'translate' that message.
And, it's a two way street.
On the nitty-gritty side, it could get cumbersome to build something blasingly fast.
I posted a heap of vb-code for inspiration
http://arduino.cc/forum/index.php/topic,115580.0.html
It essentially produces a 3d model of a infrared scanned object.

As for getting stuck in an eventhandler .. it's a question of setting your code right.
12  Using Arduino / Interfacing w/ Software on the Computer / walk through Firmata .. on: July 25, 2012, 06:14:31 am
When I look for info on Firmata, I get to look at a lot of code I generally don't understand.
Does anyone have a good link on Firmata-talk ? Or dare to take me through some basic steps.

I've employed the allInput example, and it works. It's confusing, when tapping through (in processing)
Code:
  for (int i = 0; i <= 13; i++) {
    if (arduino.digitalRead(i) == Arduino.HIGH){
i no longer represent the original pin used (I use pin 11 and it matches i=3)

I've tried to be smart and reduce the code to get a 'simple' read of an analog value .. but won't work. I'm sure there is a simper and more direct way to reach that goal than to take the allInput example apart.
The simpleAnalogFirmata example uses a callback-function "analogWriteCallback( .. )"  .. It'll have to be an accessible function in processing, but how do I recognize it there?
13  Using Arduino / Interfacing w/ Software on the Computer / Re: automatically detect USB port with arduino from the computer on: July 25, 2012, 05:36:15 am
thanks Carsten53T, but the problem is that you obtain the name of the port, not of the device. So if I have 3 com busy, for example COM3 COM8 and COM10 it is not possible to automatically detect on wich one arduino is connected to.(of course if I know the port becouse I saw it from my OS I can set it manually but this is not what I need to do)
cantore,
That's as far as I can take you.
The first time I attach a board to my pc .. I'll have to go through the procedure of finding the proper driver and 'install' it to the board. At that time, the board will be blessed with a port-name that appears to stick to that particular board and not the usb-port that it is connected to. I think that it'll be a mess to automate catching this portname as it would need an app running prior to the time you choose to connect a new board.
Even the ardino-editor doesn't do an automatic search .. atleast you may often find yourself have to choose which port to use. You can mimic that with gui in processing (make it show a drop-down list with available ports). I'm way too inexperienced to suggest what's available if you choose to look at 'port-methods' in c/c++.
Remember to pop a message if you succeed .. it would be a nice thing to master ..
14  Using Arduino / Interfacing w/ Software on the Computer / Re: automatically detect USB port with arduino from the computer on: July 24, 2012, 12:50:09 pm
Check out Processing .. in modes/java/libraries/arduino/examples/arduino_output

Code:
void setup() {
  size(470, 200);
  
  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);

On my pc println(Arduino.list()); prints the name ("Port8") of one (a port with an arduino attached) out of three ports. Outside println() Arduino.list() should be accessible for tabbing through .. right?


EDIT:
I completely forgot that it's a downloaded library
Look/get at it at
http://www.arduino.cc/playground/interfacing/processing
15  Using Arduino / Interfacing w/ Software on the Computer / Re: automatically detect USB port with arduino from the computer on: July 24, 2012, 09:21:03 am
the problem is that with arduino.list() I obtain all the serial devices connected to my computer.
Wouldn't that solve your problem? You can scrutinize each member-name in the list and have the index of the port you find.

Quote
I think for ddetecting arduino I must use a sort of handshake.
A handshake are sometimes used as part of a start-communication and sometimes fixed by a formal protocol used. If you'r in a position to use a successful handshake, you've already found your port. But, ok, I see where you'r going. I'm not sure of what functions are available, but the set I used in vb needed an eqvivalent to serial.start() before any communication. If you can assume, that your board is in a closed state ... if it's got a isOpen() .. I don't know.

Quote
The problem is that I need to listen to all the devices connected but if they are already busy (the com port is occcupied) an exception occours and from processing it seems not possible to catch the "PortInUseException". Any other suggestion to detect the port number with my arduino?
Well .. you can still set up a catch/try block ... but that way round may bring you to where your teachers told you not to go.

Paul,
you sure can catch me in the shortcomings of my expressions. I'm surprised that I get a sort of 'passed the array-limit' error on [2] when there are three available ports, that the third (arduino) on the list is available on [1] and that accessing
  • throws no error ... but how could you know ..
Pages: [1] 2 3 ... 11