Loading...
  Show Posts
Pages: 1 [2] 3 4 5
16  Forum 2005-2010 (read only) / Syntax & Programs / Re: Multiple functions one button on: April 01, 2010, 12:48:13 pm
Why can't you have arduino count the number of times your button does, say take a digital line low or high?
17  Forum 2005-2010 (read only) / Syntax & Programs / Re: Communications protocol over newsoftserial on: May 11, 2009, 10:38:45 am
This was fixed by a) reducing speed to 2400 and b) removing hardware handshaking. Conclusion is that newsoftserial cannot support hadware handshaking.
18  Forum 2005-2010 (read only) / Syntax & Programs / Re: Communications protocol over newsoftserial on: May 08, 2009, 11:32:11 am
I guess this loop member takes a little getting used to; I managed to get things rational with this code:

void loop()
{
if (commport.available() != 0)
      {
      c = (char)commport.read();
      input[counter++] = c;
      commport.flush();
      counter = 0;
      if (input[0] == '1')
            {
            Serial.print("received ");
            Serial.println(input);
            commport.print("1");
            commport.print("2");
            input[0] = 0;
            }
      else
            Serial.println("got garbage");
      }
}

I will play with this code and see were the problem was exactly - I don't see why sending 1 and 2 out should affect input counts in available(). The applet code is:

header[0] = '1';                                          // send request for ROM value
gtp.send(header);
header = gtp.receive();
if (header[0] == '1')
      {
      System.out.println("got 1 back");
      msgbody = gtp.receive();
      msgbodystring = new String(msgbody);
      System.out.println("got " + msgbodystring + " after that");
      address.setText(msgbodystring);
      }
else
      System.out.println("got garbage");

where gtp is a Java socket i/o handler and is called only once.

Ooops - spoke too soon: now I don't get the '2' back from newsoftserial.
19  Forum 2005-2010 (read only) / Syntax & Programs / Re: Communications protocol over newsoftserial on: May 07, 2009, 04:09:32 pm
Thanks for the reply, but that is innocuous and definitely not the problem.

Oh, I see where mikalhart knows that newsoftserial doesn't work right under v15. Need to wait, I guess.
20  Forum 2005-2010 (read only) / Syntax & Programs / Communications protocol over newsoftserial on: May 07, 2009, 03:44:47 pm
I am using newsoftserial8 at 9600 baud on a 328 under v15; this loop is supposed to read a character from an applet on the xport and reply; instead it goes into an infinite loop and keeps receiving characters when no more are being sent.



void loop()
{
if (commport.available() != 0)
      {
      c = (char)commport.read();
      input[counter++] = c;
      }
commport.flush();
counter = 0;
if (input[0] == '1')
      {
      Serial.print("received ");
      Serial.println(input);
      }
else
      Serial.println("got garbage");
commport.print("1");
commport.print("2");
}
21  Forum 2005-2010 (read only) / Syntax & Programs / Re: Reading my own pwm-generated voltage on: April 30, 2009, 06:11:49 pm
You're right - need either pin 2 or 3 and appropriate interrupt.
Tried that - interrupt service is for pin 2 and in the routine I try to read the analog pin 0. No dice.
I think this is not doable because interrupts are being soaked up by the pwm generator.
22  Forum 2005-2010 (read only) / Syntax & Programs / Re: Reading my own pwm-generated voltage on: April 29, 2009, 05:35:24 pm
Hi Anachrocomputer - thanks for the reply, but I need the actual value of the pwm after it hits the resistive circuit - if somebody changes the resistance that will change the pwm voltage and I have to know by how much. In fact I need both the high and low voltage parts because that tells me there is a diode in the circuit and the change in resistance is warranted.

I thought the interrupt service routine doesn't apply to any particular pin.

Right now my println always returns 0.

I tried both interrupt channels (0 and 1.)
23  Forum 2005-2010 (read only) / Syntax & Programs / Reading my own pwm-generated voltage on: April 29, 2009, 12:09:53 pm
I have (hopefully) just one more problem: I generate a pwm that goes into a resistor circuit; the resistance of the circuit could change and I need to detect that. I thought of using an interrupt to test the value of the pwm I send out, but I'm not sure that works.

Code:
int pwmpin = 11;                          // inject pwm here
int testpin = 9;                  // check pwm voltage here
volatile int state = LOW, testvalue;
 
void setup()
{
TCCR2B = (TCCR2B & 0xF8) | 3;            // ~1khz pwm
pinMode(testpin, INPUT);
attachInterrupt(0, test, CHANGE);
analogWrite(pwmpin, 64);           // ~25% duty cycle
Serial.begin(9600);
}
 
void loop()
{
Serial.println(testvalue);
delay(1000);
}

void test()
{
testvalue = analogRead(testpin);
}
24  Forum 2005-2010 (read only) / Interfacing / Re: Xbee pro series 2 reset problem on: May 03, 2010, 01:24:20 pm
An Arduino can reset if there is a bug in the code - it could be a wild pointer or some such animal.
25  Forum 2005-2010 (read only) / Development / Modifying Rapp's Xbee library for NewSoftSerial? on: April 01, 2010, 01:13:36 pm
The whole idea in the following is to allow a new constructor
XBee(rxpin, txpin);
so that it autoinitializes XBee to use the NewSoftSerial port instead
of the Serial port.

I changed XBee.h as:
#include <WProgram.h>
#include <inttypes.h>
#include <NewSoftSerial.h>     \\ <===========
but I get a "file not found" error for NewSoftSerial
I changed Xbee.h as well here:

* \author Andrew Rapp
 */
class XBee {
public:
      XBee();
      XBee(rxpin, txpin);   //<======
      // for eclipse dev only
      void setSerial(HardwareSerial serial);
      void setSerial(NewSoftSerial serial);   // <=============
but I get compiler error at XBee(rxpin, txpin);

I added line to XBee.h as in:
      uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE];
      uint8_t _rxpin, _txpin;   // <===========

I overloaded constructor in XBee.cpp as in:
#include "XBee.h"
#include "WProgram.h"
#include "HardwareSerial.h"
#include "NewSoftSerial.h"     // <===========

XBee(uint8_t rxpin, uint8_t txpin) // <==============
{
_rxpin = rxpin;
_txpin = txpin;
}

I overloaded setserial in XBee.cpp:
void XBee::setSerial(NewSoftSerial serial) { // <========
      Serial = serial(_rxpin, _txpin);
}

void XBee::setSerial(HardwareSerial serial) {
      Serial = serial;
}

I included NewSofSerial.h in XBee.cpp and added new constructor:

#include "XBee.h"
#include "WProgram.h"
#include "HardwareSerial.h"
#include "NewSoftSerial.h"

XBee(uint8_t rxpin, uint8_t txpin) // <=============
{
_rxpin = rxpin;
_txpin = txpin;
}

But I get a  few errors:

In file included from XBee.cpp:20:
/XBee.h:673: error: expected `)' before ',' token
XBee.cpp:25: error: expected `)' before 'rxpin'
XBee.cpp: In member function 'void XBee::setSerial(NewSoftSerial)':
XBee.cpp:695: error: no match for call to '(NewSoftSerial) (uint8_t&, uint8_t&)'
hardware\libraries\XBee/XBee.h:25:27: error: NewSoftSerial.h: No such file or directory

Can somebody please help - I really need this to work!
Reason: when the Nano3 (or Arduino) runs, it asks for initialization; if no new initialization parameters are submitted within 5 seconds, it runs with old parameters, so the Serial port (on USB) is needed; the XBee must run on NewSoftSerial.
My C++ is really rusty (I'm reading Stroustrup's original book as reference, that's how long it's been.)


I'm referring to Andrew Rapp's Xbee library, which is bloody useful.
26  Forum 2005-2010 (read only) / Development / Re: Can I run both ethernet server and client? on: October 14, 2009, 04:36:42 pm
In my opinion the approach provided by Lantronix is simpler, cleaner, more flexible, more rugged and precisely because you can do client/server, more powerful. I'm not affiliated with them.
27  Forum 2005-2010 (read only) / Development / Re: Can I run both ethernet server and client? on: October 14, 2009, 12:26:25 pm
Well, once you satrt saying 'Internet' you need to know at least how to program in Java. The Xport is a page server and there are several ways to have it talk to the Web - Java applets and various sorts of servlets, etc. That is a whole world in itself. You need to know this part, and it's totally separate from Arduino stuff.
However, once that's done, the Xport to Arduino comm is simple; it uses NewSoftSerial, and characters are sent back and forth. On the Xport side this happens with Java sockets executed by the Java client.

To get your feet wet the best is to look at the sample code Lantronix provides that uses sockets to run a little test program. Here it is:

Code:
import java.*;
import java.lang.*;
import java.net.*;
import java.util.*;
import java.io.*;

/*
 * This class opens a TCP connection, and allows reading and writing
 * of byte arrays.
*/

public class tcpip
{
protected Socket s = null;
public DataInputStream dis = null;
protected DataOutputStream dos = null;

public tcpip(InetAddress ipa, int port)
{
Socket s1 = null;
try
      {               // Open the socket
      s1 = new Socket(ipa.getHostAddress(), port);
      }
catch (IOException e)
      {
      System.out.println("Error opening socket");
      return;
      }
s = s1;
try
      {               // Create an input stream
      dis = new DataInputStream(new BufferedInputStream(s.getInputStream()));
      }
catch(Exception ex)
      {
      System.out.println("Error creating input stream");
      }
try
      {               // Create an output stream
      dos = new DataOutputStream(new BufferedOutputStream(s.getOutputStream()));
      }
catch(Exception ex)
      {
      System.out.println("Error creating output stream");
      }
}

public synchronized void disconnect()
{
if (s != null)
      {
      try
            {
            s.close();
            }
      catch (IOException e){}
      }
}

public synchronized void send(byte[] temp)
{
try
      {
      dos.write(temp, 0, temp.length);
      dos.flush();
      }
catch(Exception ex)
      {
      System.out.println("Error sending data : " + ex.toString());
      }
}

public synchronized void send(byte[] temp, int len)
{
try
      {
      dos.write(temp, 0, len);
      dos.flush();
      }
catch(Exception ex)
      {
      System.out.println("Error sending data : " + ex.toString());
      }
}


      // WARNING: this routine may not properly convert Strings to bytes

public synchronized void send(String given)
{
int length = given.length();
byte[] retvalue = new byte[length];
char[] c = new char[length];
given.getChars(0, length, c, 0);
for (int i = 0; i < length; i++)
      {
      retvalue[i] = (byte)c[i];
      }
send(retvalue);
}


public synchronized byte[] receive()
{
byte[] retval = new byte[0];

try
      {
      while(dis.available() == 0);  /* Wait for data */
      }
catch (IOException e){}
try
      {
      retval = new byte[dis.available()];
      }
catch (IOException e){}
try
      {
      dis.read(retval);
      }
catch (IOException e){}
return(retval);
}

public int available()
{
int avail;

avail = 0;
try
      {
      avail = dis.available();
      }
catch (IOException e) {}

return(avail);
}
}


This code uses a Java socket to talk over the Xport serial connection to the Arduino chip. The code executes as a client of the Xport page server. It is separate from what happens at the Internet (RJ) connector side on the Xport where standard http stuff occurs.

I modified this code to provide asynchronous comm on the Java side. My problem right now is (posted nearby) that asynchronous messaging on the Arduino is a problem and I don't yet know if it's incurable.
28  Forum 2005-2010 (read only) / Development / Re: Can I run both ethernet server and client? on: October 14, 2009, 11:38:23 am
I assume you are using the Xport shield. What you say is confusing. The Xport is a page server to which you connect a client (say an applet). The Xport in turn does serial tunnelling to the Arduino. That's all there is to it. This means for your app that when something happens on the Arduino, you send a message over NewSoftSerial to the Xport and it in turn notifies the applet. The applet should have asynchronous messaging capabilities.
29  Forum 2005-2010 (read only) / Development / Pin 11 in this code to generate exact 1kHz pwm? on: June 17, 2010, 08:02:29 pm
I found this code in a post - it does generate exactly 1kHz pwm - could somebody point out how to change it for pin 11 - sorry am noob on registers.

Code:
void setup()
{
  // configure hardware timer2 to generate a fast PWM on OC2B (Arduino digital pin 3)
  // set pin high on overflow, clear on compare match with OCR2B
  TCCR2A = 0x23;
  TCCR2B = 0x0C;  // select timer2 clock as 16 MHz I/O clock / 64 = 250 kHz
  OCR2A = 249;  // top/overflow value is 249 => produces a 1000 Hz PWM
  pinMode(3, OUTPUT);  // enable the PWM output (you now have a PWM signal on digital pin 3)
  OCR2B = 125;  // set the PWM to 50% duty cycle
}

void loop()
{
float floatr = 1;
  OCR2B = 125;  // set the PWM to 50% duty cycle
  for (int j = 0; j < 1000; j++)
      floatr++;
  OCR2B = 50;  // set the PWM to 20% duty cycle
  for (int j = 0; j < 1000; j++)
      floatr++;
  pinMode(3, INPUT);  // turn off the PWM
  //do some stuff;
  pinMode(3, OUTPUT);  // turn the PWM back on
}
 
30  Forum 2005-2010 (read only) / Development / Re: Looking for business related project ideas. on: April 09, 2010, 11:22:20 am
Why don't you look at some patent data on the Web - there might be the odd idea there you could improve on, or offer help with.
Pages: 1 [2] 3 4 5