Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Weird problem sending strings to serial. Some strings not holding info. on: September 12, 2013, 05:30:45 pm
Hi,

It is definatly a memory problem, ie running out.

I wnt through remming out lots of code that I did not need that came with the ps2 code for example
Code:

  //if(ps2x.Button(PSB_L3))
      //  Serial.println("L3 pressed");
     // if(ps2x.Button(PSB_R3))
       // Serial.println("R3 pressed");
     // if(ps2x.Button(PSB_L2))
      //  Serial.println("L2 pressed");
     // if(ps2x.Button(PSB_R2))
      //  Serial.println("R2 pressed");
     // if(ps2x.Button(PSB_GREEN))
     //   Serial.println("Triangle pressed");

as I am not using those button for the moment I remmed out any usage of them and lots more.
Even remming out the      //   Serial.println("Triangle pressed");  bit in the code helps.

I would still like to know how to make my code more ram efficient but for the moment I need to just rem out unneeded code.
2  Using Arduino / Programming Questions / Re: Weird problem sending strings to serial. Some strings not holding info. on: September 12, 2013, 04:46:41 pm
Ok I have deleted some of the serial.print lines I was using for debugging purposes and it seems to get better, its reporting more free ram and the code seems to be working.

I still need to add quite a bit more coding though to this project and I will hit this problem very soon.

So any advice with some examples taken from my code of how I could save ram would really be helpful.

I really dont understand what "I recommend using 'c' strings (null-terminated char arrays) instead." means.
So if you could show me an example then I could slog on and tidy my ram usage.

Thanks again.
3  Using Arduino / Programming Questions / Re: Weird problem sending strings to serial. Some strings not holding info. on: September 12, 2013, 04:33:50 pm
Hi,

I am using 1.0.5

I have just added MemoryFree.h and
      Serial.print("freeMemory()=");
    Serial.println(freeMemory());
reports 155

Could you give me some examples of how I can cut down on memory usage. I am learning C for the arduino, so Im a bit green. I have lots experience with Basic and VB etc but not much with C.

Thanks
4  Using Arduino / Programming Questions / Re: Weird problem sending strings to serial. Some strings not holding info. on: September 12, 2013, 04:18:43 pm
Hi,

here is the file

Thanks
5  Using Arduino / Programming Questions / Re: Weird problem sending strings to serial. Some strings not holding info. on: September 12, 2013, 04:13:03 pm
Hi,

1. Something is modifying Command2, or the code that fills it is not getting called for whatever reason.
I used command2 to test my original string was command1 and I am not calling anything else in that section of code. 2) how can I test for the overflow problem


I have tried pasting the code but I have exceeded the limit of 9500 characters so I cant post it, my code is
Binary sketch size: 18,706 bytes.  Could I be running out of RAM on runtime ?

Can I paste the code some other way ?

Albert
6  Using Arduino / Programming Questions / Weird problem sending strings to serial. Some strings not holding info. on: September 12, 2013, 03:45:33 pm
I have been working on a rov control project for a while now and suddenly out of the blue my serial data is not going.
After some diagnosis I have found that some strings just dont seem to send data.

To explain le me show you some code

Code:
// This is at the begining of the program where I declare all my variables, I have only pasted here the relevant ones
int JoyRXI = 0;
String Command1;
String Command2;
int slowit = 1;

//This is in the loop part of the program, with lots of other code, this is exaclty how it is in the code, nothing missing between the lines.
    Command2 = "TEST";
    Serial.print(">>>");
    Serial.print(JoyRXI);
    Serial.print("---");
    Serial.print(Command2);
    Serial.println("<<<");

When I run the serial port monitor I would expect     >>>119---TEST<<<
but I get     >>>119---<<<

It does not seem to be holding the "TEST"

This just suddenly started happening when I was modifying some code, but its not even going into that part of the program.
It was working great until today.

Please any ideas

Albert



7  Using Arduino / General Electronics / High current 5A stepper motor driver on: March 26, 2013, 11:50:09 am
Hi,

I am looking for an IC that I can connect to high current steppers ie 1.5v 2.9A and higher. That I can then drive from the arduino.
I want to use only 2 pins from the uno to drive the stepper, for example pin1 send pwm pin2 if high it forward and low if reverse.
At the moment I can do it by using 4 pwm pins and I wnat to drive more motors etc without having to add other unos etc.
By using something like the above I would use save lots on the pwm ports.

I know this exists for low current like the EasyDriver Stepper Motor Driver. But can't find for more higher loads.

Anyone know where I can find them.

Thanks
Albert
8  Using Arduino / Programming Questions / Re: Software serial routine on: December 12, 2012, 12:30:38 pm
Hi,

I have got it working with some help of examples.
I have the trasmitter side of the software and then the receiver side.
This code just sends the >A001< over and over as fast as it can, I did this to test data loss.
The A001 I will interpret in the receiver to do something for example Motor A speed =1, or servo A position 1.
in this format I can control servos, motors etc  A,B,C,D etc etc and send a value up to 999, I can always increase it to 4 or more characters.
Although by using less digits I can send more info in less time.

Transmiter code
-----------------------------------------------------------------------------------------------
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX  <<<<<   if using MEGA for transmitter use pins 10,11
void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(19200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
}

void loop() // run over and over
{
  mySerial.write(">A001<");

 if (mySerial.available()){ //Something has come into the transmitter serial port
  if(mySerial.read()=='-')// if the remote serial full, send - to slow down
  {
    delay(15);// short pause to let remote receiver time t empty some of the serial buffer
  }
 }
}


--------------------------------------------------------------------------------------------------------
receiver code

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX  <<<<<< receiver on MEGA. If using uno you can use pins 2,3.
  char ByteIn;
  String StringIn;
  int led = 13;
void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(19200);
  pinMode(led, OUTPUT); 

  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  //mySerial.println("Hello, world local?");
}

void loop() // run over and over
{
  if (mySerial.available()) // something waiting to be read on software serial port
  {
    //Serial.println(StringIn);
    Serial.println(mySerial.available());  //show buffer size, this is for info only
    if (mySerial.available() > 50)   //  serial port has 64 byte buffer so to stop it getting full and dropping bytes slow incoming transmission for a bit
    {
     mySerial.write("-"); // send a - to transmitter, could be any character as long as it matches on both sides
    }
    ByteIn = mySerial.read(); // get a byte from the serial port
    //Serial.write(ByteIn);
    StringIn = StringIn + ByteIn; // build up the incoming bytes into the string
    if (ByteIn == '<') // we have the character that tells me that is the end of that command/data.
   {
    // now do something with the string
    if (StringIn != ">A001<") // here you can now do something with the commands that have arrived the != is for not equal to, I used this for testing to see if I was getting any garbage. you should use something like if(StringIn == ">A001<") or break down the comand. get first Character(removing the >), get last 3 characters.
    {

    digitalWrite(led, LOW); 

    }
    else
    {
     digitalWrite(led, HIGH);
    }
   
    StringIn = ""; // clear the string ready to build the next one
   }
  }

}



That is working for me and I can choose any baud rate for the comms, the handshaking will pause if its coming in to fast to proccess. you can change the pause on the transmitter side if required.

Connect pins 2,3 TX,RX and ground from one arduino to the other.
If you also connect the 5v line then you dont even need to power the remote arduino. Although care must be taken if you plug servos etc in the remote one as the power drawn for both arduino will be via the first one.

Albert


9  Using Arduino / Programming Questions / Re: Software serial routine on: December 09, 2012, 02:25:22 pm
Hi,

The joystick info I will use ic2 routines that are readily available.

The 6 characters were so I can also send other information that might need more than 3 digits, future proofing my code.

The number of characters is not important its the routine I need to send and receive them correctly.

So any suggestions on the code side of things.

Albert
10  Using Arduino / Programming Questions / Re: Software serial routine on: December 09, 2012, 11:25:02 am
Hi,

GPS was not mentioned at all.

I am getting info from joystick at arduino 1 and sending info to ardurino2.

Regards
Albert
11  Using Arduino / Programming Questions / Re: Software serial routine on: December 09, 2012, 10:56:00 am
Hi,

Ok lets keep it simple.
Forgetting software serial etc

I want to send the data as per my first post via any serial option.

Can someone point me to a link with some code that closely reflects what i require ?

keeping in mind a continous stream of data to be decoded into commands.

regards
Albert
12  Using Arduino / Programming Questions / Re: Software serial routine on: December 09, 2012, 10:30:22 am
Hi,

I thought the hardware serial is used when connected via the usb to the pc and I use it to monitor and debug.

Can I use the hardware serial and also use the com port created via the ide at the same time.

My code is a mess as I have been trying several combinations so it does not look to good

Albert
13  Using Arduino / Programming Questions / Software serial routine on: December 09, 2012, 09:13:09 am
Hi,

I am working in building a rov. I am going to use a playstation controller connected to an arduino on the shore and a second arduino in the rov controlling the motors, lights servos etc.
I want to use software serial to send all the commands from shore to rov so i will only need 3 wires for control, tx,rx and ground, the other wires will be used for video etc.
my guess is that using 9600 baud should be fast enough and reliable enough but I want to be able to change the baud up and down to test reliability, responsivnes against length of cable.

I have tried using  by Tom Igoe based on Mikal Hart's example but I get funny characters on occasion (not all the time, my baudrate etc is good and I get some of the info correctly)
My guess is that as I am reading the serial port continuosly and I am reading it even when there are no bytes ready to be read so its getting a default null character, its a y with two dots on top, char 152 in the ascii table.

Basically I want to send a command from one arduino to another, for example

Send "(A000001)"  which I will decodeto something like, turn on LED A
or    "(A000000)"  turn off led A
or    "(B000120") set motor B speed to 120
or    "(C000170)" set servo C to 170

etc etc the format of the data is not important as long as I can receive it correctly.
I want to use fixed length of commands to keep it simple.
And I will be sending the commands continuosily.

If anyone can help me with the code to do the above I would be very grateful.

Regards
Albert
14  Using Arduino / Installation & Troubleshooting / Re: how connect an arduino uno and a mega to a pc at the same time for programing on: December 09, 2012, 06:42:51 am
Hi,

that worked thanks

Albert
15  Using Arduino / Installation & Troubleshooting / how connect an arduino uno and a mega to a pc at the same time for programing on: December 08, 2012, 08:36:49 pm
Hi,
I want to connect my mega and uno to my pc at the same time  so i can program them at the same time.

They are connected together via software serial and i want to change the programs as i decide on the changes.

When i change my second ide to the mega port and board the first ide also changes so both ide's seem to be linked.

Is there a way to run two ide's at the same time and they dont interfere with each other

Thanks
Albert
Pages: [1] 2