Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Programming Questions / Re: SoftwareSerial reference instance from sketch in a library? on: April 22, 2012, 07:48:03 pm
Nick,

Thanks, works well.

-ren
2  Using Arduino / Programming Questions / SoftwareSerial reference instance from sketch in a library? on: April 22, 2012, 06:00:03 pm
Hello,

I created a SoftwareSerial instance in my main sketch, mymain.ino. I want to reference that instance in an included library. I want to be able to debug the program from a softwareserial port in the main sketch and the library. So, here is what I have, I get an error when I try to DebugPort.print in the .cpp file.

//mymain.ino
#include <SoftwareSerial.h>
#include <MyLibrary.h>
SoftwareSerial DebugPort(2,3);
...
DebugPort.print("something");
...

//mylibrary.cpp
...
DebugPort.print("something");  -->get an error from compiler DebugPort was not declared in this scope
...

Thanks,

-ren




3  Using Arduino / Motors, Mechanics, and Power / Re: Arduino 5V output - Switch a device on/off with relay on: April 12, 2012, 08:46:52 am
Runaway Pancake,

Thanks for the explanation about the diode. How do you chose the proper size of diode?

Thanks,

-ren
4  Using Arduino / Motors, Mechanics, and Power / Re: Arduino 5V output - Switch a device on/off with relay on: April 11, 2012, 11:03:51 pm
Hello,

Initially I was going to use the reed relay, but I happen to have a npn 3904 transistor, so I am going to give that a try. I will have a digital pin connected to the base. I can figure out the resistor needed to give me enough current Ib, to allow the current needed for the load(camera) Ic. I will put 5V to load(camera) to the collector of the transistor. I have seen some people online putting a diode(flyback) in parallel to the load to eliminate excess voltage. I understand that this is to protect against a voltage spike at the collector of the transistor. I probably don't need this in this case because this device will not build up a charge, but I am curious as how the value of the diode is determined if I decided to add. Also, in some instances online I have seen where a resistor placed between the load and the collector, why? If it requires too much explaining, could you point me to a reference to learn about this?

Thanks,

-ren
5  Using Arduino / Networking, Protocols, and Devices / Determine hardware serial speed during program execution? on: April 09, 2012, 10:52:14 pm
Hello,

I am switching the serial read/write speed throughout my program. Is there a function in the serial library that will return the current speed of the hardware serial port? I suppose that I could check the registers, has anybody done that already?

Thanks,

-ren
6  Using Arduino / Motors, Mechanics, and Power / Re: Arduino 5V output - Switch a device on/off with relay on: April 09, 2012, 10:33:15 pm
Thanks I will give it a try!
7  Using Arduino / Motors, Mechanics, and Power / Arduino 5V output - Switch a device on/off with relay on: April 09, 2012, 09:56:22 pm
Hello,

I am running a camera that requires 5V 80-100mA. I can use the 5V output of arduino, no problem. I tried running from a digital pin(which I believe provides ~40mA), this does not work. So I tied 3 together to get my mA requirement. I rather not use all of these pins just to provide power to camera, can I put a relay on the 5V out instead?

Thanks,

-ren
8  Using Arduino / Networking, Protocols, and Devices / Re: Arduino mega(1280) hardware serial communication problem w/jpeg camera on: March 29, 2012, 08:40:10 am
Paul,

I updated the post(turned smileys off).I am using Arduino 1.0. I had to update the sparkfun library to work with 1.0. Yes, I did an independent test at 38400 sending / receiving to the mega serial port, seemed to work fine.

What is particularly confusing is that I have run this same code with the 328p @ 38400 with software serial without problems. Only change is moving to mega and updating to hardware serial port. The mega should output the lines as the arduino with software serial, similar to lines below. Instead I am getting back the response header(7600320000) and end data(7600320000) in the output.

040509070705080b0a0b0b0b0a0b0a0c0e110f0c0d100d0a0b0f140f10121213
ffd8fffe00240c041098000000000000000000000000000000f00040010c0032

Thanks,

-ren

9  Using Arduino / Networking, Protocols, and Devices / Arduino mega(1280) hardware serial communication problem w/jpeg camera on: March 28, 2012, 11:09:13 pm
Hello,

I am using this camera(http://www.sparkfun.com/products/10061) with arduino(m328p) & arduino mega(1280). The arduino(m328p) works with this camera using software serial at 38400. I would like to achieve higher baud rates, so I hooked up the camera to the mega onto the Serial1 hardware interface. It appears to be sending the messages correctly, however I am having a problem reading the data back from the camera. There appears to be a latency issue. A message of 16 bytes is sent to the camera, then it sends back a response header(5bytes 7600320000) + data(32 bytes) + end data(5bytes 7600320000). I am only interested in the data, which are the image bytes. This is done in an iterative process, by incrementing the read address by amount read on each iteration. The library I am using is from sparkfun(found at the link for the camera above), it has a routine to capture this data, which is shown below. I am reading the data back onto the Arduino IDE serial monitor. I placed the output of the arduino(328p) and mega below to help resolve this issue.

The only change I have to Sparkfun library is switching from software serial to hardware serial 1. I suspect the problems lies in one of 3 things.
1. There is an issue with latency on the mega serial ports, due to the serial library?
2. There is a difference in the variables sent back from arduino vs. mega, uint16_t vs. uint8_t?
3. There is a problem with address or read_size variable that is causing a problem in the send command, although I verified that it sends the correct command, seems to be working.  

Can anybody help guide me to a solution?

Thanks,

-ren

//these variables are declared in the program as such
const int read_size=32; //constant amount of bytes to receive
int address=0; //value is incremented each time thru loop


int JPEGCamera::readData(char * response, int address){
int count=0;
Serial1.flush();
int i =0;
//Send the command to get read_size bytes of data from the current address
for(i; i<8; i++)Serial1.print(READ_DATA);
Serial1.write((uint8_t)(address>>8));
Serial1.write((uint8_t)address);
Serial1.write((uint8_t)0x00);
Serial1.write((uint8_t)0x00);
Serial1.write((uint8_t)(read_size>>8));
Serial1.write((uint8_t)read_size);
Serial1.write((uint8_t)0x00);
Serial1.write((uint8_t)0x0A);

//reads off header
for(int i=0; i<5; i++){while(!Serial1.available());Serial1.read();}

count=0;
while(count < read_size)
{
while(!Serial1.available());
*response++=Serial1.read();
count+=1;
}

return count;
}
38400 baud. Arduino software serial. Output back to serial monitor using PrintHex83. 2 iterations shown.
040509070705080b0a0b0b0b0a0b0a0c0e110f0c0d100d0a0b0f140f10121213
ffd8fffe00240c041098000000000000000000000000000000f00040010c0032

...

38400 baud. Arduino mega using hardare serial 1. Output back to serial monitor using PrintHex83. Notice how 7600320000 is drifting,eventually settles into set location, note lower bottom right. Multiple iterations shown.
ffd8fffe0024f30b5f20000000000000000000000000000000f00040010b0032
7600320000120b510451040000ffdb0084000302020202020302020203030303
76003200007600320000040408060605070a090a0a0a090a090b0c100d0b0c0f
0e0f1011127600320000760032000012120b0d13151311151011121101030303
0408110b0a0b1111111176003200007600320000111111111111111111111111
1111111111111111111111111111117600320000760032000011111111111111
1111fffe0005000000ffc000110800f001400301763200007600320000210002
ffc401a200000105010101010101000000000000003200007600320000030405
0b01000301010101010101010100000000000001023200007600320000060708
02010303020403050504040000017d0102030004113200007600320000314106
7114328191a1082342b1c11552d1f02433627282090000760032000018191a25
3435363738393a434445464748494a5354555657580000760032000063646566
7475767778797a838485868788898a929394959697000076003200009aa2a3a4

...

38400 baud. Communicating directly using serial monitor. Output back to serial monitor encoded as hex. Includes response header + data + end data. 2 iterations shown.
76 00 32 00 00 FF D8 FF FE 00 24 00 02 50 4B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F0 00 40 01 0D 00 32 76 00 32 00 00
76 00 32 00 00 12 0B 51 04 51 04 00 00 FF DB 00 84 00 03 02 02 02 02 02 03 02 02 02 03 03 03 03 04 07 04 04 04 76 00 32 00 00
10  Using Arduino / Project Guidance / Re: Set Arduino serial baud rate above 115200 ->230400, 256000,307200,614400 on: March 26, 2012, 06:48:16 pm
arduino duemilanove std usb cable
11  Using Arduino / Project Guidance / Re: Set Arduino serial baud rate above 115200 ->230400, 256000,307200,614400 on: March 25, 2012, 05:07:15 pm
robtillaart,

Yes, I see that now.  I did get 230400 to work, had data bits set incorrectly to 7 in the terminal. If I keep the speeds listed on the mega 328 datasheet for 16mhz, it works well, as you stated. I tried pushing it to 2mbs using the code you posted(see below). I didn't do any error checking, but it seemed to work fine. By the way, if anybody is interested, the speeds listed in the datasheet for 16mhz are 230400/250000/500000/1000000. Also it doesn't have it listed, but indicates 0% error up to 2mbs using u2xn=1.

Thanks for the help!

-ren

void setup()
{
  
  Serial.begin(2000000);   // !! 115200, 230400, 345600,   460800 X
  //delay(1000);
  //Serial.println("Hello World");
}

void loop()
{
  
  unsigned long t1 = millis();
  for (long i=0; i< 10000; i++)
  {
   Serial.println("12345678");  // 10 bytes incl \r\n  
  }
  Serial.println(millis() - t1);
}
12  Using Arduino / Project Guidance / Set Arduino serial baud rate above 115200 ->230400, 256000,307200,614400 on: March 25, 2012, 02:26:59 pm
Hello,

I would like to increase the speed of the serial port above 115200 baud. I have tried the test below. Usb cable from pc connected to arduino 328p. Tried to view results in br@y terminal 1.9b. It did not print anything(if I try same test with 115200, it works fine). Do I have to modify hardwareserial.cpp in order to achieve these higher speeds?

Thanks,

-ren


void setup()                   
{
  Serial.begin(256000);         
 
  Serial.println("Hello world!"); 
}

void loop()                     
{
                               
}
13  Using Arduino / Project Guidance / Re: Serial baud rate adjustment without reset? on: March 25, 2012, 02:17:17 pm
robtillaart,

Thanks, I suspected that could call begin twice, but I wasn't sure...thanks for clearing it up.

-ren
14  Using Arduino / Project Guidance / Serial baud rate adjustment without reset? on: March 25, 2012, 03:05:02 am
Hello,

Is it possible to adjust the baudrate of the serial port without a reset?

Thanks,

-ren
15  Using Arduino / Programming Questions / Re: Quickest way to search a uint16_t array for a uint16_t value? on: March 24, 2012, 08:09:54 pm
Thanks Nick I will give it a try!
Pages: [1] 2 3 ... 6