Arduino
-
- Posts: 6
- Joined: 31 Jan 2024, 14:09
Arduino
Can anybody help me how to integrate Arduino-programms (for relays and servo's) into AstroArt-programms. I need that to also control remotely the calibration-lamps in my spectroscope and flip-mirror on it, together with all the other AstroArtprogramming.
-
- Posts: 20
- Joined: 09 May 2019, 08:02
Re: Arduino
Hi,
I'm currently using such an integration for opening and closing the roof of my observatory after checking the relevant status of either the telescope (it shall be parked) and the roof itself. This last control is made by using a magnetic switch. The relevant commands, that are defined in the Arduino sketch, are passed to Arduino via the serial port connected to Arduino itself. I guess that you have already developed the relevant sketch.
Alessandro
I'm currently using such an integration for opening and closing the roof of my observatory after checking the relevant status of either the telescope (it shall be parked) and the roof itself. This last control is made by using a magnetic switch. The relevant commands, that are defined in the Arduino sketch, are passed to Arduino via the serial port connected to Arduino itself. I guess that you have already developed the relevant sketch.
Alessandro
-
- Posts: 6
- Joined: 31 Jan 2024, 14:09
Re: Arduino
Hi,
what my issue is: the communication between Astro Art and Arduino via serial commands.
Not Arduino sketches only the interface with Astro Art.
what my issue is: the communication between Astro Art and Arduino via serial commands.
Not Arduino sketches only the interface with Astro Art.
-
- Posts: 20
- Joined: 09 May 2019, 08:02
Re: Arduino
Hi Frank,
I'd like to share the code calling Arduino to verify if the roof is opened or closed. It was developed several years ago by a friend for his own observatory. I modified a litlle the original one:
QUOTE
RoofStatusCheck()
End
Function RoofStatusCheck()
cmd_serl=7 'serial port set by Arduino
fed_1str$="ing1"
fed_2str$="ing2"
roof_opened="y"
roof_closed="y"
' LETTURA SENSORI IN INGRESSO ***************************************
' rilevatore di tetto aperto
if roof_opened="y" then
serial.connect(cmd_serl) 'connection to the serial port
pause(2)
serial.send(fed_1str$) 'lancio stringa di interrogazione ingresso 1
pause(2)
status_ig$=(serial.receive())
status_i1$=(status_ig$[1])
serial.disconnect()
if status_i1$="1" then print "Roof status: opened ("+status_i1$+")"
endif
'fine rilevatore di tetto aperto
'rilevatore di tetto chiuso
if roof_closed="y" then
serial.connect(cmd_serl) 'connessione alla porta seriale
pause(2)
serial.send(fed_2str$) 'lancio stringa di interrogazione ingresso 2
pause(2)
status_ig$=(serial.receive())
status_i2$=(status_ig$[1])
serial.disconnect()
if status_i2$="1" then print "Roof status: closed ("+status_i2$+")"
endif
'fine rilevatore di tetto chiuso
end function
UNQUOTE
Regards
Alessandro
I'd like to share the code calling Arduino to verify if the roof is opened or closed. It was developed several years ago by a friend for his own observatory. I modified a litlle the original one:
QUOTE
RoofStatusCheck()
End
Function RoofStatusCheck()
cmd_serl=7 'serial port set by Arduino
fed_1str$="ing1"
fed_2str$="ing2"
roof_opened="y"
roof_closed="y"
' LETTURA SENSORI IN INGRESSO ***************************************
' rilevatore di tetto aperto
if roof_opened="y" then
serial.connect(cmd_serl) 'connection to the serial port
pause(2)
serial.send(fed_1str$) 'lancio stringa di interrogazione ingresso 1
pause(2)
status_ig$=(serial.receive())
status_i1$=(status_ig$[1])
serial.disconnect()
if status_i1$="1" then print "Roof status: opened ("+status_i1$+")"
endif
'fine rilevatore di tetto aperto
'rilevatore di tetto chiuso
if roof_closed="y" then
serial.connect(cmd_serl) 'connessione alla porta seriale
pause(2)
serial.send(fed_2str$) 'lancio stringa di interrogazione ingresso 2
pause(2)
status_ig$=(serial.receive())
status_i2$=(status_ig$[1])
serial.disconnect()
if status_i2$="1" then print "Roof status: closed ("+status_i2$+")"
endif
'fine rilevatore di tetto chiuso
end function
UNQUOTE
Regards
Alessandro
-
- Posts: 6
- Joined: 31 Jan 2024, 14:09
Re: Arduino
Hi Alessandro,
thanks for your message.
It seems that the communication with Arduino via serial.connect works (checked with Serial.println) but the script does not go into the loop after the setup part.
The communication with serial.send(string) in Astro Art and Serial.receive () in my Arduino script does not work.
What is your script in Arduino to receive "ing1" or "ing2" correctly and execute further as you want?
It would be great when it also works with my spectroscope (Neon-lamp, Flat-lamp, servo for flip mirror).
I hope you will reply, frank
thanks for your message.
It seems that the communication with Arduino via serial.connect works (checked with Serial.println) but the script does not go into the loop after the setup part.
The communication with serial.send(string) in Astro Art and Serial.receive () in my Arduino script does not work.
What is your script in Arduino to receive "ing1" or "ing2" correctly and execute further as you want?
It would be great when it also works with my spectroscope (Neon-lamp, Flat-lamp, servo for flip mirror).
I hope you will reply, frank
-
- Posts: 20
- Joined: 09 May 2019, 08:02
Re: Arduino
Hi Frank,
the part of the Arduino sketch to receive "ing1" and "ing2" is as follows:
QUOTE
// ******************
// **** INGRESSI ****
// ******************
fed1 = digitalRead(BUTTON1); // legge il valore dell'input e lo conserva
// controlla che l'input sia HIGH (pulsante premuto)
if (fed1 == HIGH) {
stato1 = 1;
}
else {
stato1 = 0;
}
fed2 = digitalRead(BUTTON2); // legge il valore dell'input e lo conserva
// controlla che l'input sia HIGH (pulsante premuto)
if (fed2 == HIGH) {
stato2 = 1;
}
else {
stato2 = 0;
}
fed3 = digitalRead(BUTTON3); // legge il valore dell'input e lo conserva
// controlla che l'input sia HIGH (pulsante premuto)
if (fed3 == HIGH) {
stato3 = 1;
}
else {
stato3 = 0;
}
val = Serial.readString();
if(val == "ing1" ){ //interrogo l'ingresso 1 (Apertura tetto)
Serial.println(stato1);
}
if(val == "ing2" ){ //interrogo l'ingresso 2 (Chiusura tetto)
Serial.println(stato2);
}
if(val == "ing3" ){ //interrogo l'ingresso 3 (Telescope park)
Serial.println(stato3);
}
UNQUOTE
unfortunately is written in Italian, but I think you can easily understand the meaning of the notes.
However I can send you the whole sketch as it is because I have not written it.
Hope this can help.
Alessandro
the part of the Arduino sketch to receive "ing1" and "ing2" is as follows:
QUOTE
// ******************
// **** INGRESSI ****
// ******************
fed1 = digitalRead(BUTTON1); // legge il valore dell'input e lo conserva
// controlla che l'input sia HIGH (pulsante premuto)
if (fed1 == HIGH) {
stato1 = 1;
}
else {
stato1 = 0;
}
fed2 = digitalRead(BUTTON2); // legge il valore dell'input e lo conserva
// controlla che l'input sia HIGH (pulsante premuto)
if (fed2 == HIGH) {
stato2 = 1;
}
else {
stato2 = 0;
}
fed3 = digitalRead(BUTTON3); // legge il valore dell'input e lo conserva
// controlla che l'input sia HIGH (pulsante premuto)
if (fed3 == HIGH) {
stato3 = 1;
}
else {
stato3 = 0;
}
val = Serial.readString();
if(val == "ing1" ){ //interrogo l'ingresso 1 (Apertura tetto)
Serial.println(stato1);
}
if(val == "ing2" ){ //interrogo l'ingresso 2 (Chiusura tetto)
Serial.println(stato2);
}
if(val == "ing3" ){ //interrogo l'ingresso 3 (Telescope park)
Serial.println(stato3);
}
UNQUOTE
unfortunately is written in Italian, but I think you can easily understand the meaning of the notes.
However I can send you the whole sketch as it is because I have not written it.
Hope this can help.
Alessandro
-
- Posts: 6
- Joined: 31 Jan 2024, 14:09
Re: Arduino
Goodmorning Allesandro,
What I saw that you use a "pause(2)" in the Astro Art script, maybe that is important, further I always used only the Arduino command "Serial.read()" or "Serial.parseInt()" but did not know the "Serial.ReadString()" command. I'm going to try.
On the other hand I use the "switch()"-command in stead of "if" statements.
When the script runs properly I'll send it to you.
Thanks, for your prompt and adequate reply.
see you laterr, frank
What I saw that you use a "pause(2)" in the Astro Art script, maybe that is important, further I always used only the Arduino command "Serial.read()" or "Serial.parseInt()" but did not know the "Serial.ReadString()" command. I'm going to try.
On the other hand I use the "switch()"-command in stead of "if" statements.
When the script runs properly I'll send it to you.
Thanks, for your prompt and adequate reply.
see you laterr, frank
-
- Posts: 20
- Joined: 09 May 2019, 08:02
Re: Arduino
Hi Frank,
I would like to enclose the file file with the whole code for Arduino so you can have the full picture.
Alessandro
I would like to enclose the file file with the whole code for Arduino so you can have the full picture.
Alessandro
- Attachments
-
- OssCar_001.txt
- (5.92 KiB)
-
- Posts: 6
- Joined: 31 Jan 2024, 14:09
Re: Arduino
Hi Alessandro,
I had some time to try several options (as you will see) but still did not work.
I tries to use the variable "Lhires" as an integer, so that I can use Serial.parseInt and the switch-command, as a String, as a Char but none worked.
I then put a Serial.println in the setup-par to look whether there would be a communication between the two languages, but even that did not worked.
Maybe you see what is wrong. I hope you can, greetings frank.
The Aduino board is an Uno and it communicates via com 16
I give you first the short script in AstroArt:
Serial.Connect (16)
pause(2)
Serial.Send("0")
pause(2)
Serial.Send("1")
pause(2)
Serial.Disconnect()
Now the more extensive Arduino sketch:
//Servo- and String-libraries added
#include <Servo.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
//Servo definition
Servo Myservo;
// integer definition for servo
int pwmPin = 10;
// integers for relays defined
int relay_1 = 4;
int relay_2 = 7;
int relay_3 = 8;
int relay_4 = 12;
// integer definition for duration
// int duration;
// character for the Switch variable
// '0' Servo will move the mirror in diagonal position
// '1' Servo will move the mirror vertical position
// '10' Neon-light, 1st relay, will be de-activated
// '11' Neon-light, 1st relay, will be activated
// '30' Flat-light, 3th relay, will be de-activated
// '31' Flat-light, 3th relay, will be activated
void setup() {
// make communication with baudrate
Serial.begin(9600); // COM-port = 16
// attach the servo to a pin
Myservo.attach(pwmPin);
Serial.println("y"); //check whether there is a connection build by sending just a character
}
void loop() {
// based on the input via serial command
// and variable Lhires, an action will be made:
if (Serial.available() > 0) {
while (Serial.available() > 0) {
String Lhires;
//strcpy(str,Serial.read());
//int Lhires = atoi(str);
//int Lhires = Serial.read();
//int Lhires = Serial.parseInt();
Lhires = Serial.readString();
Serial.println(Lhires);
if (Lhires == "0"){
Myservo.write(-90); // Servo will move the mirror in diagonal position
delay(1000);
} else {Myservo.write(+90); // Servo will move the mirror in diagonal position
delay(1000);}
/*switch (Lhires) {
case 0: // Do the following when Lhires equals 0
Myservo.write(-90); // Servo will move the mirror in diagonal position
delay(1000);
break;
case 1: // Do the following when Lhires equals 1
Myservo.write(+90); // Servo will move the mirror vertical position
delay(1000);
break;
case 10: // Do the following when Lhires equals 10
digitalWrite(relay_1, LOW); // Neon-light, 1st relay, will be deactivated
delay(1000);
break;
case 11: // Do the following when Lhires equals 11
digitalWrite(relay_1, HIGH); // Neon-light, 1st relay, will be activated
delay(1000);
break;
case 30: // Do the following when Lhires equals 30
digitalWrite(relay_3, LOW); // Flat-light, 3th relay, will be de-activated
delay(1000);
break;
case 31: // Do the following when Lhires equals 31
digitalWrite(relay_3, HIGH); // Flat-light, 3th relay, will be activated
delay(duration);
break;
default:
Serial.println ("Wrong input"); // Input is unknown, send a message back
break;
}
*/
//return; // Command will be returned to Astro-Art
}
}
return;
}
I had some time to try several options (as you will see) but still did not work.
I tries to use the variable "Lhires" as an integer, so that I can use Serial.parseInt and the switch-command, as a String, as a Char but none worked.
I then put a Serial.println in the setup-par to look whether there would be a communication between the two languages, but even that did not worked.
Maybe you see what is wrong. I hope you can, greetings frank.
The Aduino board is an Uno and it communicates via com 16
I give you first the short script in AstroArt:
Serial.Connect (16)
pause(2)
Serial.Send("0")
pause(2)
Serial.Send("1")
pause(2)
Serial.Disconnect()
Now the more extensive Arduino sketch:
//Servo- and String-libraries added
#include <Servo.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
//Servo definition
Servo Myservo;
// integer definition for servo
int pwmPin = 10;
// integers for relays defined
int relay_1 = 4;
int relay_2 = 7;
int relay_3 = 8;
int relay_4 = 12;
// integer definition for duration
// int duration;
// character for the Switch variable
// '0' Servo will move the mirror in diagonal position
// '1' Servo will move the mirror vertical position
// '10' Neon-light, 1st relay, will be de-activated
// '11' Neon-light, 1st relay, will be activated
// '30' Flat-light, 3th relay, will be de-activated
// '31' Flat-light, 3th relay, will be activated
void setup() {
// make communication with baudrate
Serial.begin(9600); // COM-port = 16
// attach the servo to a pin
Myservo.attach(pwmPin);
Serial.println("y"); //check whether there is a connection build by sending just a character
}
void loop() {
// based on the input via serial command
// and variable Lhires, an action will be made:
if (Serial.available() > 0) {
while (Serial.available() > 0) {
String Lhires;
//strcpy(str,Serial.read());
//int Lhires = atoi(str);
//int Lhires = Serial.read();
//int Lhires = Serial.parseInt();
Lhires = Serial.readString();
Serial.println(Lhires);
if (Lhires == "0"){
Myservo.write(-90); // Servo will move the mirror in diagonal position
delay(1000);
} else {Myservo.write(+90); // Servo will move the mirror in diagonal position
delay(1000);}
/*switch (Lhires) {
case 0: // Do the following when Lhires equals 0
Myservo.write(-90); // Servo will move the mirror in diagonal position
delay(1000);
break;
case 1: // Do the following when Lhires equals 1
Myservo.write(+90); // Servo will move the mirror vertical position
delay(1000);
break;
case 10: // Do the following when Lhires equals 10
digitalWrite(relay_1, LOW); // Neon-light, 1st relay, will be deactivated
delay(1000);
break;
case 11: // Do the following when Lhires equals 11
digitalWrite(relay_1, HIGH); // Neon-light, 1st relay, will be activated
delay(1000);
break;
case 30: // Do the following when Lhires equals 30
digitalWrite(relay_3, LOW); // Flat-light, 3th relay, will be de-activated
delay(1000);
break;
case 31: // Do the following when Lhires equals 31
digitalWrite(relay_3, HIGH); // Flat-light, 3th relay, will be activated
delay(duration);
break;
default:
Serial.println ("Wrong input"); // Input is unknown, send a message back
break;
}
*/
//return; // Command will be returned to Astro-Art
}
}
return;
}
Re: Arduino
Hi, when making a custom communication protocol based on serial ports, it's easier to test the device with a terminal software (PuTTY, RealTerm, etc.) maybe something similar is already included in the Arduino software.
To debug I would start with something like:
To debug I would start with something like:
Code: Select all
Lhires = Serial.readString();
if (Lhires == "Servo-90") {
Myservo.write(-90); // Servo will move the mirror in diagonal position
Serial.println("OK-90");
delay(1000);
};
if (Lhires == "Servo+90") {
Myservo.write(+90); // Servo will move the mirror in diagonal position
Serial.println("OK+90");
delay(1000);
};
-
- Posts: 6
- Joined: 31 Jan 2024, 14:09
Re: Arduino
Ok, I'll try Processing as terminal software.
BTW for debugging I had activated only that part of the sketch; most of it was already made as comment
BTW for debugging I had activated only that part of the sketch; most of it was already made as comment