Show Posts
Pages: 1 2 [3] 4 5
31  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);
}
32  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.
33  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.
34  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.
35  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.
36  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.
37  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
}
 
38  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.
39  Forum 2005-2010 (read only) / Development / Re: Asynchronous messaging over NewSoftSerial on: October 14, 2009, 06:15:35 pm
Sorry about the ambiguity - I have either a server processor or a communications processor connected to an Arduino, but in both cases there is a control server either directly, or indirectly talking to the Arduino and expecting responses. The problem is that because one processor doesn't know what the other is doing things are asynchronous.
Eventually this will become a network with 100's of Arduinos. So the problem is non-trivial.
An Arduino/Arduino combo is not that far-fetched if I run out of other ideas.
40  Forum 2005-2010 (read only) / Development / Asynchronous messaging over NewSoftSerial on: October 14, 2009, 11:47:39 am
I'm a bit stuck in that I have a co-processor arrangement where the machines talk to each other, but I don't always know when they do it; it could happen while one machine is streaming data to the other.
Without separate i/o buffers on the port or equivalently full duplex comms I may have trouble.
Is there any foreseeable possibility of full duplex operation?
41  Forum 2005-2010 (read only) / Troubleshooting / Re: Arduino -issues with Win7? on: March 01, 2010, 08:12:11 pm
You don't mention if you are using Win7 pro in XP mode - I can foresee problems in Win7 native mode myself. About to go there.
42  Forum 2005-2010 (read only) / Troubleshooting / Arduino Nano V 3.0 usb fails if Vin powered on: March 01, 2010, 05:20:35 pm
I chose the Nano to be embedded in a pcb, but I notice in testing that when the device is powered via Vin (12V), when the usb connector is plugged in, Windows complains that the port does not work. This is annoying as it means an extra jumper in the pcb to disconnect power if the usb connect is ever needed. Anyone else come across this or am I doing something stupid?
43  Forum 2005-2010 (read only) / Interfacing / Re: XBee Arduino Library for API mode on: November 16, 2009, 04:31:06 pm
Hi Andrew,
I'm using a modified development board that I wire-wrapped; it has 3.3V ttl/RS232 level converter, led's and grounds, etc. Works well. I am keeping the wire-wrap between pins 9 and 10 on the Xbee on that board. I must say X-CTU presents a steep learning curve for a simple program, but...
NOW your libraries seem to work!!!!!!!! Got RemoteAtCommand.pde to work, anyway - proceeding with rest. I'll download your new version first. Thanks for doing that.

Yup, sampling works as well - good stuff!
44  Forum 2005-2010 (read only) / Interfacing / Re: XBee Arduino Library for API mode on: November 15, 2009, 02:21:33 pm
Hi Andrew,

Looks like my problem is that I'm using an Xbee as a Zigbee when it should be a Znet 2.5 - Digi is driving me nuts. I also didn't pay attention to something you mentioned earlier because I didn't know the difference between Zigbee and Znet. This explains the error return from your calls. I am trying to write this (coordinator) file now:

Code:
XB24-B_ZigBee_1147.mxi
80
0
251
1147
0
[A]ID=234
[A]SC=1FFE
[A]SD=3
[A]NJ=FF
[A]DH=0
[A]DL=FFFF
[A]NI=
[A]BH=0
[A]AR=FF
[A]DD=20000
[A]NT=3C
[A]NO=0
[A]PL=4
[A]PM=1
[A]EE=0
[A]EO=0
[A]BD=3
[A]NB=0
[A]D7=1
[A]D6=0
[A]AP=2
[A]AO=0
[A]SP=20
[A]D0=1
[A]D1=0
[A]D2=0
[A]D3=0
[A]D4=0
[A]D5=1
[A]P0=1
[A]P1=0
[A]P2=0
[A]LT=0
[A]RP=28
[A]PR=1FFF
[A]IR=0
[A]IC=0
[A]V+=0

Note it's called Zigbee, but drop down in X-CTU calls it Znet 2.5. It just will not do the write - keeps coming back with an error for EE. Changing EE and E0 produces an error for BD, etc.
Probably time to talk to the X-CTU boys...
45  Forum 2005-2010 (read only) / Interfacing / Re: XBee Arduino Library for API mode on: November 13, 2009, 03:06:37 pm
Yes, fantastic - I even solved my x-ctu problems (see under xbee issues thread).
Did you update your library so I can download new version? Then I'll have another go at it.

Forgot to mention - my problems were solved thanks to another posting of yours.

I'm getting a compiler error on Arduino v15 in the second statement:

RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, irCmd, irValue, sizeof(irValue));
remoteAtRequest.setApplyChanges(false);
 
error: expected constructor, destructor, or type conversion before '.' token

Tried casting but that didn't work either.
Pages: 1 2 [3] 4 5