Arduino

Scripts and programs to automate Astroart
Post Reply
frankvuijsters
Posts: 5
Joined: 31 Jan 2024, 14:09

Arduino

Post by frankvuijsters » 31 Jan 2024, 14:14

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.

AlessandroMaitan
Posts: 19
Joined: 09 May 2019, 08:02

Re: Arduino

Post by AlessandroMaitan » 31 Jan 2024, 15:34

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

frankvuijsters
Posts: 5
Joined: 31 Jan 2024, 14:09

Re: Arduino

Post by frankvuijsters » 04 Mar 2024, 18:12

Hi,

what my issue is: the communication between Astro Art and Arduino via serial commands.
Not Arduino sketches only the interface with Astro Art.

AlessandroMaitan
Posts: 19
Joined: 09 May 2019, 08:02

Re: Arduino

Post by AlessandroMaitan » 05 Mar 2024, 09:33

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

frankvuijsters
Posts: 5
Joined: 31 Jan 2024, 14:09

Re: Arduino

Post by frankvuijsters » 09 May 2024, 17:15

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

AlessandroMaitan
Posts: 19
Joined: 09 May 2019, 08:02

Re: Arduino

Post by AlessandroMaitan » 10 May 2024, 19:58

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

frankvuijsters
Posts: 5
Joined: 31 Jan 2024, 14:09

Re: Arduino

Post by frankvuijsters » 11 May 2024, 08:25

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

AlessandroMaitan
Posts: 19
Joined: 09 May 2019, 08:02

Re: Arduino

Post by AlessandroMaitan » 12 May 2024, 06:27

Hi Frank,
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)

frankvuijsters
Posts: 5
Joined: 31 Jan 2024, 14:09

Re: Arduino

Post by frankvuijsters » 17 May 2024, 18:18

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;
}

Post Reply