Show Posts
Pages: [1] 2 3
1  Using Arduino / Microcontrollers / Re: How to completely remove the bootloader? on: October 29, 2013, 01:40:48 am
You are right, I should leave more detail here:

FIrstly I made the circuit following  this video:  http://youtu.be/yJo29VMXt90
 And I've been confirmed with a original m328p (without Bootload fresh unboxed) the circuit works as it should be. (In atmel studio 6 I can read the target Voltage and ID) and I do check the voltage of the circuit with a Multimedia. It's correct.

May it be something about Fuses?

Thanks.
2  Using Arduino / Microcontrollers / Re: How to completely remove the bootloader? on: October 28, 2013, 06:42:22 pm
Hi Nick,
I've meet tonight such a interesting problem:

I've tried to use my AVR Dragon to program a atmega328p with arduino bootloader. But it just can't get the correct ID of the chip. then I've tried the m328p on a arduino board. I works just fine (Blink a led on pin13). Then I tried my adafruit usbtiny. Avrdude told me "Initialization failed, rc = -1".

I just wanna tried some AVR with my old Arduino. But it seems the bootload stopped the programming process?

Any Tipp? ; )
3  Using Arduino / Programming Questions / Re: Trying to get things to happen once only at the start of a sketch on: July 06, 2013, 05:34:01 am
can you post a link of your Relay board?
4  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 05, 2013, 02:34:04 pm
update:

A few days before, I tried to Email the engeneers of the motor's company (Nanotec). Today I got the answer from them: (German)
Quote
Die Steuerung senden ein Echo des Befehls, wenn dieser Befehl erkannt und verarbeitet wurde.
 

z.B.

 

-> #1A\r                              Befehl vom Anwender

 

Etwa 10-40ms

 

<- 1A\r                                 Antwort der Steuerung

 

Nach dieser Antwort ist die Steuerung bereit einen neuen Befehl entgegen zu nehmen.

Ist es nicht möglich, die Antwort auszuwerten, sollte ein Detail von 50ms gewählt werden,

um sicher zu sein.
The motor have to process the command and then after done the command it feeds the echo. And till now I can actually send the new one. If I send it "too early", The motor won't buffer it at all...
Really pain in the ass. But anyway I got the point. That means I can really handle it now!
5  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 05, 2013, 03:24:51 am
Gammon, It works!
I used your last example to parse from Serial coming Data. Bravo!

But I do did a tiny modification on it:
in the "void loop(){}" I changed "if (Serial.available())" to "while (Serial.available())". If I don't, the Serial buffer will be overflowed (But I'm not pretty clear about this point.)

Thank you again!

P.S. The function that works perfectly now is:
Code:
const char startOfNumberDelimiter = 'I';
const char endOfNumberDelimiter   = '\r';

void shaftEncoder(){
Serial2.print("#1I\r");
while (Serial2.available())
processInput();
}

void processNumber (const long n)
{
Serial.println (n);
}  // end of processNumber

void processInput ()
{
static long receivedNumber = 0;
static boolean negative = false;

byte c = Serial2.read ();

switch (c)
{
case endOfNumberDelimiter:
if (negative)
processNumber (- receivedNumber);
else
processNumber (receivedNumber);

// fall through to start a new number
case startOfNumberDelimiter:
receivedNumber = 0;
negative = false;
break;

case '0' ... '9':
receivedNumber *= 10;
receivedNumber += c - '0';
break;

case '-':
negative = true;
break;

case '+':
negative = false;
break;

default:
Serial.println("!");
break;

} // end of switch
}  // end of processInput

6  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 04, 2013, 12:14:59 pm
Quote
The command pages I looked at indicate that each command causes a reply. Why aren't you concerned about the responses?
Yeh, Pauls. You are almost right. I don't need much bidirectional communication between arduino and step motor. 99% command is "single directional". I'm not sure in really professional area how many motor will be controlled by his own build-in microcontroller and in my motor (Nanotec PD4-N) there is even a "shaft encoder" that can record the absolutely position of the motor. In my project I have to read the value through Serial port. So I have to do care about if the command is correctly be gotten by motors. And I think my still works not great function that read this value should be enhanced.
Code:
/*****
* Purpose: get the actual drehzahl of the motor. (Right-rotation add the Drehzahl, left reduce it)
* Argument: void
* Return: void
* input: void
* output: the position value "drehWert" read from the integrated circuit of the motor
*****/
void Drehgeber() {
char signAscii;
int sign; //Here can not be "byte", that can't save negative value.
int  length;

Serial2.println("#1I"); //"ask" motor for the position value.
if (Serial2.available()) {
length = Serial2.available(); //if a bit is readed, than it doesn't exist in the serial buffer anymore.
if (Serial2.read() == 49){ //wenn erste Stelle eine '1' ist (Motoradresse),(this part should be refactoringed to let the other motor also work)
if (Serial2.read() == 73){ //wenn nächste Stelle ein 'I' ist (Drehgeberposition)
drehwert = 0;
signAscii = Serial2.read(); //Ascii '+' or '-'
if (signAscii == '+') //wenn Ascii Wert = 43 dann positiv
sign = 1; //store the polarity of the absolute position value from shaft encoder.
else if (signAscii == '-') //wenn Ascii Wert = 45 dann negativ
sign = -1;
for (int i=(length-5); i>=0; i--){
int Wert = Serial2.read();
drehwert = drehwert + ((Wert - 48) * pow(10,i)); //calculate the read value
}
drehwert = drehwert * sign; //here set the direction of the absolute positioin value.
}
Serial.print(" position:");
Serial.println(drehwert);
}
else Serial.println("ERROR, Drehgeber crashed!");
while(Serial2.read()>0); //clear the Serial2's buffer
}
}

Protocol:
Ask command format:
"#1I\r" -- '#'-command start, '1'-motor address,'I'-command asking for shaft encoder read value, '\r'-CR end symbol
Answer command format:
"1I00000000\r" -- '1'-motor address, 'I"-command asking for shaft encoder read value, "00000000"-read value,'\r'-CR end symbol
The read value don't have fixed bits. I thought the parsing method is very poor... And I can't make it better any further.

BTW: In 2011, Pauls you helped me this year to build a perfect working Xbee communication. I appreciate your kindly help. Here I'd like to thank you once more.  smiley
7  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 04, 2013, 09:35:34 am
Quote
It's function is different depending on the IDE version.
Thank you really so much! You help me at this very point! Great!

And then comes the new problem!!
On theory, we can wait for all the Serial communication done through the help of "Serial.flush();" in a very "smart" way. But even so, I still can't get the right answer from the motor? I mean like different delay time have different answer from the motor. I don't set delay, but Serial.flush(); between each command to let the code wait for the Serial communication. But still can't got all the answers!

What a tricky & expensive motor!
8  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 04, 2013, 05:33:00 am
Quote
This is close to becoming a cross-post. Your  other thread also talks about serial problems. How about, next time, actually providing a link to "the project" rather than making us guess, or possibly solve the same problem twice?
Nick, cause I'm a new bie, I'm not sure what you mean. Should I put the total project description on somewhere here?
The other post is for the rs-485 network (half duplex) of the weight transmitters. This one is for the even trickier rs-485 for motors (full duplex).
This is the link of the step motor that I use:
http://us.nanotec.com/products/228-pd4-n59n60-plug-drive-stepper-motor-with-integrated-rs485-canopen-closedloop-positioning-control/
9  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 04, 2013, 05:23:24 am
Hi Nick, Thanks for your patient answer and the tipps! Next time I'll try my best to describe my project better!
Quote
Is this it?
Yes, this is it. But I'm sorry the attached code isn't up to date. I put here this time a new one.

Today I've tried again if the "Serial2.flush();" works. And it not at all.
Detail: in the setup(), I send a bunch of commands to the motor, in order to let it surely work at the proper state:
Code:
        sendToMotor("#1S"); //motor stop
sendToMotor("#1g32"); //Schrittmodus einstellen (Vollschritt etc.)
sendToMotor("#1:ramp_mode=0"); //Trapez-Rampe(0), Sinusrampe(1), Jerkfreerampe(2) Seite37
sendToMotor("#1p5"); // '5' - Drehzahlmodus, '2' - "Absolute Positionierung" Seite47
sendToMotor("#1u100"); //Minimalfrequenz Seite49
sendToMotor("#1o8000"); //Maximalfrequenz Seite50
sendToMotor("#1b41649"); //equal to 3Hz/ms, set acceleration Seite51
sendToMotor("#1d1");//'0' - links, '1' - rechts
sendToMotor("#1I"); //Drehgeber auslesen
sendToMotor("1#U0");//'0' - aus, '1' - Korrektur nach einer Fahrt, '2' - Kor. waehrend einr Fahrt Seite23
Then, I should get the right answer from each command, And I did it with:
Code:
        while(Serial2.available())
Serial.write(Serial2.read());
while(Serial2.read()>0); //".flush();" don't work for Serial2
Question 1: I can get the answer from the motor, and even I write a "flush()" before this snippet, I can still get the answer from motor. I write like this:
Code:
        Serial2.flush();
while(Serial2.available())
Serial.write(Serial2.read());
while(Serial2.read()>0); //".flush();" don't work for Serial2


Question 2: This should be the real tricky problem happening all through my communication with motors!
the funciton "sendToMotor()" is pretty simple:
Code:
/*****
* Purpose: send a String to motor's rs485 port
* Argument: String message
* return: void
* input: string message
* output: send message through Serial port direct to motors.
*****/
void sendToMotor(String message) {
Serial2.print(message);
Serial2.print('\r');
delay(10); //the delay time should be even smaller to speed up the system update speed
}
If I send commands through this command, and the delay() in it is only be set as 5ms, I can't get all the expected answers. If it's 10ms, I can get the correct amount of answers. (I attach the screen shoots of the serial monitor in these two situations).
My thought: I send command too fast, that the serial port of some side or even both sides of the serial communication overload.
10  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 03, 2013, 02:27:26 pm
Quote
The problem is not the serial data, then. There is something about the motor and it's handling of serial data. You need to investigate that, not blame the HardwareSerial class.
Pauls, thanks! I thought the problem is from the Arduino side. Yeh, It seems not. And I discover, the Serial communication of the Motor is pretty tricky. I've to investigate more time on them!

BTW: I discovered today, the .flush() for Serial2 don't works at all!?
11  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 03, 2013, 06:45:34 am
All Code can be find here: http://forum.arduino.cc/index.php?topic=174489.msg1295473#msg1295473
the really Tricky Part is in here (in the main code's "manualDrive.ino")
Code:
Serial2.println("#1p5"); //Set the motor's mode to "Rotate and speed changeable mode".
Serial2.println("#1d0"); //Set the motor's rotate direction to "left".
Serial2.println("#1pA"); //Let the motor start to execute the movement.
Theses command should be at one time sent to set the motor in a certain "modi" and do the specified thing. If I don't add a 8ms delay() between them, the effect is that the motor start to rotate but the direction is the opposite one.
BTW, the motor is Nanotec P4D (working on 24V)
12  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 03, 2013, 05:36:44 am
Quote
Why? Why do you need to delay? What happens if you don't? Are you just assuming that a delay will eliminate the need to read and deal with any response?
Ye, some kinda of. For instance, some commands are used to set a "question" for motor. If I send the command without delay(), motors will not answer this command or they just do not do the thing that the command asked. With the help out my oscilloscope, I "fine tune" all the questions with a "proper" delay(), in order to let the command have enough time to be sent, than I write "If (Serial2.available()) {}...".
13  Using Arduino / Networking, Protocols, and Devices / Re: Better Serial library? & Why we have to make delay after sending info. in Serial on: July 03, 2013, 04:50:47 am
On my MAC and Windows are all 1.0.4. Cause the project that I'm working on is for me too huge now. I'm using actually Atmel Studio 6.1 + Visual Micro (Plug-in) to program the code and They call the compiler of Arduino IDE I think to do the compiling work and upload.
14  Using Arduino / Networking, Protocols, and Devices / Better Serial library? & Why we have to make delay after sending info. in Serial on: July 03, 2013, 02:28:35 am
I'm working on the project need to use RS-485 network. Each time I send ASCII code through Serial port, I have to make a delay() for the communication. The delay time depends on the length of the info. If I have many code to send & Receive, It become a really though time for me. Is there some one know a better Serial port library, or any tips for this problem?
Thanks!
15  Using Arduino / Networking, Protocols, and Devices / Re: How to create my code CRC for a message??? on: July 03, 2013, 02:15:11 am
I think you should use "XOR" to get the value. I'm also working on some kinda of the same project, that use RS-485
Hope the Info can help.‚
Pages: [1] 2 3