Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: the challenge: FIRMATA over Ethernet Shield w MultiSerialMega and SPI on: April 08, 2013, 01:06:10 pm
I guess my first question is regarding the MultiSerial bit -
I wonder should I change >

FirmataClass firmata(ethernet);

to>
FirmataClass firmata(serial);

then move everything out of the main loop and just do something like>

Code:
void setup() {
  // initialize both serial ports:
  Serial.begin(57600);
  Serial1.begin(57600);
}

void loop() {
  // read from port 1, send to port 0:

  ser = [Serial,Serial1]

  if (ethernet.available()) {
    int inByte = ethernet.read();
    ser.write(inByte);
  }
  
  if (ser.available()) {
    int inByte = ser.read();
    ethernet.write(inByte);
  }

...fooTheRest()
2  Using Arduino / Programming Questions / Re: the challenge: FIRMATA over Ethernet Shield w MultiSerialMega and SPI on: April 08, 2013, 12:35:45 pm
Here is my Python code for the client/controller, which is currently being run from a Windows PC

Keep in mind that the "COM#" - is a Virtual Serial Port mapped to the ip address of my Arduino.

Nothing real special here, just for testing a few pins. I have not written in my attempt to establish a second connection yet, but it should be no different than the first.



Code:
# -*- coding: utf-8 -*-
"""
#==============================================================================
                #                .~- monster.py ~-.
                #
                #                 Created on 1/7/13
                #
                #                   @author: paul
                #
                #                 ~ Monster Project ~
#==============================================================================

"""
from pyfirmata import *

# try: board = Arduino('/dev/ttyACM1')
# except: board = Arduino('/dev/ttyACM0')
#     except:

try:
    board = ArduinoMega('COM3')
except:
    print '''
    lights are on but nobodys home
            CONN FAILED
    '''

motora = 11
motorb = 3
temp1 = 5
light = 13

board.digital[motora]._set_mode(PWM)
board.digital[motorb]._set_mode(PWM)
board.digital[light]._set_mode(PWM)

board.analog[temp1].enable_reporting()

it = util.Iterator(board)
it.start()

def lspd(x):
    board.digital[motora].write(x)

def rspd(x):
    board.digital[motorb].write(x)

def readtemp():
    return board.analog[temp1].read()

def setlight(x):
    board.digital[light].write(x)



that together with > https://github.com/paulakg4/ArduinoCommander-ethernet/blob/master/Firmata/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino
and one device should work just fine..

My thought is to sort of splice together StandardFirmataEthernet with MultiSerialMega.ino
Code:
/*
  Mega multple serial test
 
 Receives from the main serial port, sends to the others.
 Receives from serial port 1, sends to the main serial (Serial 0).
 
 This example works only on the Arduino Mega
 
 The circuit:
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:
 
 created 30 Dec. 2008
 modified 20 May 2012
 by Tom Igoe & Jed Roach
 
 This example code is in the public domain.
 
 */


void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }
  
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte);
  }
}
..which would be run on the ArduinoMega

then on the connected ArduinoUno I would be running an unmodified copy of the FirmataEthernet (with diff IP)

So the Mega would first act as sort of a 'dumb hub' passing along all ethernet data to Serial1 before looking at it itself.
3  Using Arduino / Programming Questions / the challenge: FIRMATA over Ethernet Shield w MultiSerialMega and SPI on: April 08, 2013, 11:56:15 am
I decided to repost this as a new topic because I've found very little on using Firmata over Ethernet, so hopefully this will help someone -
... if not at least I will be able to find it. see the original topic here for reference http://arduino.cc/forum/index.php/topic,116816.msg1192129.html#msg1192129>



Basically what I want to do is control two boards - both running the Firmata Library - using one Ethernet shield.

My setup is>

|A|- ArduinoMega 2560 + Seeed Ethernet Shield (v1) + [sketch1]
|
pins[17,18][5v,grd] tied to
           X
pins[1,0][vin,grnd] on
|
|B|ArduinoUno R3 + Arduino Motor Shield(external power supply) + [sketch2]


Im able to connect board A no problem but can't seem to ping or connect to board B

My Sketches are based on the 'StandardFirmataEthernet' sketch which can be found here>

https://github.com/paulakg4/ArduinoCommander-ethernet/blob/master/Firmata/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino

it requires you to overwrite the current Ethernet library - but it works great with just one device.

On the host side(PC) Im using the PyFirmata library for Python>

https://github.com/paulakg4/pyFirmata

Im also using HW VSP3 - Virtual Serial Port to create my socket for PySerial, but Id like to get that written into my code >
 http://www.hw-group.com/products/hw_vsp/index_en.html

first let me show you my code...
4  Using Arduino / Programming Questions / Re: Ethernet Simultaneous Cient and Server? on: April 08, 2013, 11:27:55 am
If you dont mind coming along for the ride, I'd like to branch this out to a new thread>
 Ive found very little information on ethernet + firmata, and Im pretty sure this could work, but Im really terrible with these conditional loops (if thats what theyre called).

>> http://arduino.cc/forum/index.php/topic,159228.0.html
5  Using Arduino / Programming Questions / Re: Ethernet Simultaneous Cient and Server? on: April 08, 2013, 11:00:47 am
well I cant get it to fit in here but all I did was insert this into the first line of setup()
Code:
void setup()
{
  Serial.begin(57600);
  Serial1.begin(57600);     <+++Added


Serial.println("setup()");

#ifdef DHCP
 // IP by DHCP
Serial. ....
 

and this at the beginning of loop()

Code:
void loop()
{
  
------------------------------------------<+++Added
    if (Serial1.available()) {
    int inByte = Serial1.read();
    ethernet.write(inByte);
  }
  
  // read from port 0, send to port 1:
  if (ethernet.available()) {
    int inByte = ethernet.read();
    Serial1.write(inByte);
  }
 <+++Added -------------------------------------------------

  byte pin, analogPin;

  /* DIGITALREAD - as fast as possible, check for changes and output them to the
   * FTDI buffer using Serial.print()  */
  checkDigitalInputs();  

  /* SERIALREAD - processing incoming messagse as soon as possible, while still
   * checking digital inputs.  */
  while(firmata.available())
    firmata.processInput();

  /* SEND FTDI WRITE BUFFER - m....

Am I on the right the track?
6  Using Arduino / Programming Questions / Re: Ethernet Simultaneous Cient and Server? on: April 08, 2013, 10:48:01 am

I got really excited for a minute, I thought I was going to get to tell the great Paul S. that he was mistaken  smiley-wink
but your not entirely wrong - nor entirely right. Check this out>

https://github.com/paulakg4/ArduinoCommander-ethernet/blob/master/Firmata/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino

it requires you to overwrite the current Ethernet library (which is why technically your right) - but it works great with just one device.

I should mention on the client side I am connecting through the Pyfirmata library for Python.

7  Using Arduino / Programming Questions / Re: Ethernet Simultaneous Cient and Server? on: April 08, 2013, 09:56:49 am
So - Im working on something very similar but slightly different, hoping Paul S or Zoomcat might help me out.

Im wanting to do basically the same thing except I want to control two boards - both running the Firmata Library - using one Ethernet shield.

My setup is>

{A}ArduinoMega 2560 + Seeed Ethernet Shield (r1) + [sketch1]
|
pins[17,18][5v,grd] tied to
           X
pins[1,0][vin,grnd] on
|
{B}ArduinoUno R3 + Arduino Motor Shield(external power supply) + [sketch2]


Im able to connect board A no problem but can't seem to ping or connect to board B

(see next post for sketch[])
8  Using Arduino / Networking, Protocols, and Devices / Re: *resoled* Serial Commands work from Serial Monitor but not from Processing. on: February 10, 2012, 07:49:52 pm
Awesome thanks! I have seen others that seemed wrap their commands in <>  but was unsure of how to implement it. That helps alot.

By the way.. Once I merged the working serial controls into my actual project I found that I was able to leave off the delay in processing and keep just the 1ms delay in the Arduino and everything worked ok.

Im pretty sure it was because I moved all of this:
Code:
if(val1 == "led") {
  analogWrite(led, n2);
}

if(val1 == "tst") {
analogWrite(led, 125);
}
    readString="";
  }

into a seperate function, so the readString is only getting flushed after the comparisons are made.

9  Using Arduino / Networking, Protocols, and Devices / Re: *updated* Serial Commands work from Serial Monitor but not from Processing. on: February 10, 2012, 07:08:49 pm
PaulS if you are able to get this working smoothly without using delay please do let me know!

Also I did change the serial speed in the last version I posted but it was working at lower speeds also.

10  Using Arduino / Networking, Protocols, and Devices / Re: *updated* Serial Commands work from Serial Monitor but not from Processing. on: February 10, 2012, 07:06:01 pm
Ok I got it working pretty smoothly now. I played around with the delay in the Arduino sketch and put one in the Processing sketch as well.
You can test this out using the TouchOSChttp://hexler.net/software/touchosc app which is currently free (but limimted) for Android and a few bucks for IOS. Probably worth the money considering you can design your own controls etc (currently IOS only)..

Heres my working Arduino Sketch
Code:

String readString, val1, val2;

const int led = 13;

void setup() {
  Serial.begin(57600);
  Serial.println("Lets Do Somethin");
}

void loop() {

  while (Serial.available()) {
   delay(1);
    if (Serial.available() >0) {
char c = Serial.read();  //gets one byte from serial buffer
readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
// Serial.println(readString); //see what was received
        val1 = readString.substring(0, 3);
val2 = readString.substring(3, 6);

// Serial.println(val1);  
// Serial.println(val2);

int n1; //declare as number
int n2;

// char carray1[6]; //magic needed to convert string to a number
// val1.toCharArray(carray1, sizeof(carray1));

char carray2[6];
val2.toCharArray(carray2, sizeof(carray2));
n2 = atoi(carray2);

if(val1 == "led") {
  analogWrite(led, n2);
}

if(val1 == "tst") {
analogWrite(led, 125);
}
    readString="";
  }
}
 

And the working Processing sketch
Code:
import oscP5.*;        //  Load OSC P5 library
import netP5.*;        //  Load net P5 library
import processing.serial.*;    //  Load serial library

Serial arduinoPort;        //  Set arduinoPort as serial connection
OscP5 oscP5;            //  Set oscP5 as OSC connection
boolean sliderNeedsRedraw = true;
boolean square4NeedsRedraw = true;
int [] sliderStrip = new int [5];
float [] fader = new float [6];

int redbutton = 0;
int red2button = 0;//  redbutton lets us know if the button is on or off
int greenbutton = 0;
int green2button = 0;
int [] button = new int [8];  

String command = "";

void setup() {
  size(325,500);      
  noStroke();            
    oscP5 = new OscP5(this,8000);  
   arduinoPort = new Serial(this, Serial.list()[0], 57600);    
}

void oscEvent(OscMessage theOscMessage) {  
     String addr = theOscMessage.addrPattern();
  
  
    if(addr.indexOf("/1/toggle") !=-1){  
      int i = int((addr.charAt(9) )) - 0x30;   // returns the ASCII number so convert into a real number by subtracting 0x30
      button[i]  = int(theOscMessage.get(0).floatValue());     //  Puts button value into button[i]
  }
  
  
  if(addr.indexOf("/1/fader") !=-1){ // one of the faders
     String list[] = split(addr,'/');
     int i = int(list[2].charAt(5) - 0x30);
     fader[i]  = theOscMessage.get(0).floatValue();
     int j = int(fader[i]*255);

    command = "led" +j +"  " +0x0A;
    arduinoPort.write(command);
//    arduinoPort.write(0x0A);

    }
//    addr = "";
    delay(5);
}

void draw() {
 background(50);        // Sets the background to a dark grey, can be 0-255

   if(button[1] == 0){        //  If button button 1 if off do....
    redbutton = 0;        // Sets redbutton color to 0, can be 0-255
  }
  
  if(button[1] == 1){        // If button button 1 is ON do...
  redbutton = 255;        // Sets redbutton color to 255, can be 0-255
  }
   if(button[2] == 0){        //  If button button 1 if off do....
    red2button = 0;        // Sets redbutton color to 0, can be 0-255
  }
 if(button[2] == 1){        // If button button 1 is ON do...
  red2button = 255;        // Sets redbutton color to 255, can be 0-255
  }
   if(button[3] == 0){        //  If button button 1 if off do....
    greenbutton = 0;        // Sets redbutton color to 0, can be 0-255
  }
 if(button[3] == 1){        // If button button 1 is ON do...
  greenbutton = 255;        // Sets redbutton color to 255, can be 0-255
  }
   if(button[4] == 0){        //  If button button 1 if off do....
    green2button = 0;        // Sets redbutton color to 0, can be 0-255
  }
 if(button[4] == 1){        // If button button 1 is ON do...
  green2button = 255;        // Sets redbutton color to 255, can be 0-255
  }


fill(0,redbutton,0);            // Fill rectangle with redbutton amount
   rect(25, 450, 50, 50);    // Created an ellipse at 50 pixels from the left...
                // 50 pixels from the top and a width of 50 and height of 50 pixels
                
fill(0,red2button,0);          
   rect(100, 450, 50, 50);    
                
fill(0,greenbutton,0);
   rect(175, 450, 50, 50);  
                
                
fill(0,green2button,0);            
   rect(250, 450, 50, 50);    
                


}


When you run the processing sketch it only shows 4 buttons not the slider which is the only value being looked for by the Arduino sketch. It works though. In the TouchOSC app i was using the 'Simple' template, tab 1.
11  Using Arduino / Networking, Protocols, and Devices / Re: Serial Commands work from Serial Monitor but not from Processing. on: February 10, 2012, 04:59:55 pm
Ok so this is wierd

I got it working... I thought by adding the port.write(10)

while messing with it I had noticed that when I shut the program down, terminating the connection the light would sometimes light up.. like it was processing the command when the serial connection ended.

So I did some test cases with different buttons sending different commands and finally success when sending 10.

I started messing with it and it seems to be working now even without the 10...

However im noticing that when I use the slider which sends 0-255 as I slide up and down the values are being recieved by the arduino because the xbee rx is flashing.. But it doesnt register them
However if I tap different positions on the slider it does register on the led.

Any thoughts? Maybe I need to adjust the delay in the arduino sketch?
12  Using Arduino / Networking, Protocols, and Devices / Re: Serial Commands work from Serial Monitor but not from Processing. on: February 10, 2012, 11:32:55 am
Oh sorry, I must have posted the wrong version of my code. Originally I was using n2 as the value. That is what was working in the serial monitor but not from Processing.
13  Using Arduino / Networking, Protocols, and Devices / Re: Serial Commands work from Serial Monitor but not from Processing. on: February 10, 2012, 11:15:07 am

I had tried different combinations of the various variable states and it seems that was the only way I could get it to work through the terminal. But I will go back and try again so I can report what happens.

Thanks for the reply.
14  Using Arduino / Networking, Protocols, and Devices / *resolved* Serial Commands work from Serial Monitor but not from Processing. on: February 09, 2012, 11:26:50 pm
Hi guys, Im working on a project that takes OSC commands from my phone, parses them, then sends them to my arduino via 2 Xbees.

Im pretty sure I have everything set up right thus far but there seems to be some problem with the way my Processing sketch sends the serial data to the arduino.

The arduino sketch takes 6 characters, first 3 identify the command, second three are the value.

If I open up Arduinos serial monitor and type the command
Code:
led255
the led value is properly written. It works.

Using Putty I have to go to 'Terminal' settings and check the option 'Force On' for Local line ending. Then it works as well.

However when my Processing sketch sends the data its not being read. I feel like it has something to do with line endings or something.

The processing sketch first prints the values for debug before writing to terminal so Im pretty sure theyre right..

Here is the Processing sketch:
Code:
import oscP5.*;        //  Load OSC P5 library
import netP5.*;        //  Load net P5 library
import processing.serial.*;    //  Load serial library

Serial arduinoPort;        //  Set arduinoPort as serial connection
OscP5 oscP5;            //  Set oscP5 as OSC connection
boolean sliderNeedsRedraw = true;
boolean square4NeedsRedraw = true;
int [] sliderStrip = new int [5];
float [] fader = new float [6];

int redbutton = 0;
int red2button = 0;//  redbutton lets us know if the button is on or off
int greenbutton = 0;
int green2button = 0;
int [] button = new int [8];    //  Array allows us to add more toggle buttons in TouchOSC

void setup() {
  size(325,500);        // Processing screen size
  noStroke();            //  We don’t want an outline or Stroke on our graphics
    oscP5 = new OscP5(this,8000);  // Start oscP5, listening for incoming messages at port 8000
   arduinoPort = new Serial(this, Serial.list()[0], 9600);    // Set arduino to 9600 baud
}

void oscEvent(OscMessage theOscMessage) {   //  This runs whenever there is a new OSC message

    String addr = theOscMessage.addrPattern();  //  Creates a string out of the OSC message
    if(addr.indexOf("/1/toggle") !=-1){   // Filters out any toggle buttons
      int i = int((addr.charAt(9) )) - 0x30;   // returns the ASCII number so convert into a real number by subtracting 0x30
      button[i]  = int(theOscMessage.get(0).floatValue());     //  Puts button value into button[i]
    // Button values can be read by using button[0], button[1], button[2], etc.
    
 
  }
  if(addr.indexOf("/1/fader") !=-1){ // one of the faders
       String list[] = split(addr,'/');
     int i = int(list[2].charAt(5) - 0x30);
     fader[i]  = theOscMessage.get(0).floatValue();
     int j = int(fader[i]*255);
     int fadeval = j; // map(j,0,100,0,255);
  String sendme = "led" +j;
   println(sendme);  // uncomment to see x values
    arduinoPort.write(sendme +" ");
       sliderNeedsRedraw = true;
    }
}

void draw() {
 background(50);        // Sets the background to a dark grey, can be 0-255

   if(button[1] == 0){        //  If button button 1 if off do....
    arduinoPort.write("r");    // Sends the character “r” to Arduino
    redbutton = 0;        // Sets redbutton color to 0, can be 0-255
  }
 if(button[1] == 1){        // If button button 1 is ON do...
  arduinoPort.write("R");    // Send the character “R” to Arduino
  redbutton = 255;        // Sets redbutton color to 255, can be 0-255
  }
   if(button[2] == 0){        //  If button button 1 if off do....
    arduinoPort.write("w");    // Sends the character “r” to Arduino
    red2button = 0;        // Sets redbutton color to 0, can be 0-255
  }
 if(button[2] == 1){        // If button button 1 is ON do...
  arduinoPort.write("s");    // Send the character “R” to Arduino
  red2button = 255;        // Sets redbutton color to 255, can be 0-255
  }
   if(button[3] == 0){        //  If button button 1 if off do....
    arduinoPort.write("r");    // Sends the character “r” to Arduino
    greenbutton = 0;        // Sets redbutton color to 0, can be 0-255
  }
 if(button[3] == 1){        // If button button 1 is ON do...
  arduinoPort.write("R");    // Send the character “R” to Arduino
  greenbutton = 255;        // Sets redbutton color to 255, can be 0-255
  }
   if(button[4] == 0){        //  If button button 1 if off do....
    arduinoPort.write("w");    // Sends the character “r” to Arduino
    green2button = 0;        // Sets redbutton color to 0, can be 0-255
  }
 if(button[4] == 1){        // If button button 1 is ON do...
  arduinoPort.write("s");    // Send the character “R” to Arduino
  green2button = 255;        // Sets redbutton color to 255, can be 0-255
  }


fill(0,redbutton,0);            // Fill rectangle with redbutton amount
   rect(25, 450, 50, 50);    // Created an ellipse at 50 pixels from the left...
                // 50 pixels from the top and a width of 50 and height of 50 pixels
                
fill(0,red2button,0);          
   rect(100, 450, 50, 50);    
                
fill(0,greenbutton,0);
   rect(175, 450, 50, 50);  
                
                
fill(0,green2button,0);            
   rect(250, 450, 50, 50);    
                


}




And the Arduino sketch:
PLEASE IGNORE COMMENTS
Code:

String readString, val1, val2;

const int led = 13;

void setup() {
  Serial.begin(9600);
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10);
    if (Serial.available() >0) {
char c = Serial.read();  //gets one byte from serial buffer
readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
Serial.println(readString); //see what was received

// expect a string like 07002100 containing the two servo positions

        val1 = readString.substring(0, 3); //get the first four characters
val2 = readString.substring(3, 6); //get the next four characters

Serial.println(val1);  //print ot serial monitor to see results
Serial.println(val2);

int n1; //declare as number
int n2;

char carray1[6]; //magic needed to convert string to a number
val1.toCharArray(carray1, sizeof(carray1));

char carray2[6];
val2.toCharArray(carray2, sizeof(carray2));
n2 = atoi(carray2);

if(val1 == "led") {
  analogWrite(led,'val2');
}

    readString="";
  }
}
 
15  Development / Other Hardware Development / Re: Weird L293D and SN754410 behaviour on: February 09, 2012, 11:44:26 am

How many volts are you passing into it? The SN754410 has thermal shutdown protection, and I think I read that when its enabled it functions the same as the 'fast breaking' which if you watch will kinda make the motor fidget back and forth.

Pages: [1] 2