Jump to content
Welcome to Backyard Astronomy Space - please register to gain access to all of our features. Click here for more details. ×
SmallWorldsForum Microscopy and macro photography - a companion forum to BYA ×

Gina's Observatory Roll-Off-Roof Automation - Work in Progress


Gina

Recommended Posts

When I came to fit the ESP32 connectors and motor driver board to the strip board I found a small change was required - moved the ESP32 by one strip.  This is the new connection diagram.

ControlBox2.thumb.png.4c1b85c6c75aa60a9ef89000d4b6ed11.png
  • Like 1
Link to comment
Share on other sites

  • Replies 77
  • Created
  • Last Reply

Top Posters In This Topic

  • Gina

    63

  • MarkAR

    6

  • Jkulin

    2

  • silentrunning

    2

Top Posters In This Topic

Posted Images

Nearly finished the soldering for the control box.  After finishing that off the next stage is to alter the Arduino sketch to suit the ESO32.  This involves changing the allocation of GPIO pins and changing the code from connections to a Raspberry Pi to use MQTT messages over WiFi which is entirely in the ESP code.

For the WiFi control via MQTT, the code sets up links to receive messages for controlling the roof and for sending messages to show the status of the roof ie Open, Closed, Opening, Closing and the motor current. Plus any fault condition.

The GPIO connections for the ESP32 are :-
        D13 - Din - green button - (Close Button)
        D12 - Din - red button - (Stop Button)
        D14 - Din - white button - (Open Button)
        D27 - Din - closed limit switch
        D26 - Din - open limit switch
        D35 - Din - rain sensor
        D33 - Dout - InA
        D32 - Dout - InB
        D34 - ADC - CS (Motor Current)

Turning this round to become code gives :-

int pbClosePin = 13;  // Close Push Buttonint pbStopPin = 12;   // Stop Push Buttonint pbOpenPin = 14;   // Open Push Buttonint detRainPin = 35;  // Rain detector//int MotorInAPin = 33;  // Motor In Aint MotorInBPin = 32;  // Motor In B//int MotorCSPin = 34;  // Motor Current Sense
Link to comment
Share on other sites

Thank you Terry ?

I think I have the code just about finished may be able to see about testing it tomorrow.  I've also brought the roof motor unit indoors ready for testing.  Had posted a link to the code but noticed a mistake so have withdrawn it - I'll post again shortly.

 

Link to comment
Share on other sites

Have you ever thought of compiling this into an instruction manual for others who may be attempting the same outcome?

  Maybe your chance to get published , maybe the JK Rowlin of AstroEngineering?

image.png.a1489f78454a66c284f99d6976540804.png

 

Roger

  • Like 1
Link to comment
Share on other sites

Posted by: @ApophisAstros

Have you ever thought of compiling this into an instruction manual for others who may be attempting the same outcome?

  Maybe your chance to get published , maybe the JK Rowlin of AstroEngineering?

image.png.837e65bbc69525f212a8a438a0b4144d.png

 

Roger

Hadn't thought of it but an interesting idea - thank you Roger ? 

 

Link to comment
Share on other sites

Had a look at what connectors I have and came up with a 4 pin one for the connections for the limit switches and rain sensor contacts.  There are other connectors required.  Power in and Gnd, motor wires, limit switches to LEDs and power/gnd to rain sensor. but these don't connect to the stripboard

So far - a new wiring diagram.

ControlBox3.thumb.png.faaecc22961f82d2b3254ad440a16da0.png

 Connector on stripboard for limit switches and rain sensor contacts plus Gnd.  Green stars are breaks in the stripboard.

 

Link to comment
Share on other sites

I have my triple bench PSU on the table for testing things and connected it up.  Also connected the motor and tested it by linking each input in turn to Vdd (+5v) with a jumper wire in the ESP32 socket.  Success!!  It runs fine in both directions.  Next thing is to upload the sketch to the ESP32 and plug it in for testing.

Link to comment
Share on other sites

Uploaded sketch to ESP32 and tested with the Serial Monitor.  MQTT messages arrived fine at the ESP from the Dashboard,  Then disconnected it from the USB port on computer and plugged it into socket on stripboard and powered up.  Power light came on but the motor did not run from the MQTT messages.  Nor did it run from the push buttons on the box!!  Checked that the push buttons were working with DMM and they were.  +3.2v unpressed and 0v pressed.  I shall need to set up more testing and and add some fault-finding code to the sketch.

Guess it's a case of "Slowly slowly catchy monkey!"...  ? 

 

Link to comment
Share on other sites

A bit more progress.  Control messages are getting through and status messages are coming back.  So that part is working alright.  Next to see why the motor driver isn't being turned on.

Link to comment
Share on other sites

Having had time to think about this I reckon I may know why the motor isn't being run.  To do with the limit switches not being connected and the code thinking the motor is already running.  Now to test that hypothesis.

Link to comment
Share on other sites

Corrected a couple of things in the code making more of it work but two things remain.  Motor still not running and it wants to close the roof all the time!

OK - found why it wants to close the roof - it thinks it's raining even without the rain sensor connected so now investigating that.

Later - Changed RainSensor pin and now it no longer thinks it's raining and the controls mostly work when the ESP32 is disconnected.  But once Stopped it doesn't respond to Open or Close so something else to find!

Link to comment
Share on other sites

Thank you ? 

It's dawned on me why I can't seem to get things to work.  I'm running a test system and this isn't simulating the whole thing. Once opening or closing of the roof is started, nothing can happen until finished ie. the appropriate limit switch is triggered at the end of the run. Until that happens, all other commands except emergency stop are blocked. I had forgotten that and wondered why I couldn't run the motor to simulate moving the roof back and forth.

Now I plan to produce a cut-down version of the code to test just what I have.

Link to comment
Share on other sites

Went right back to basics and found a fundamental silly mistake.  Now have the motor running both ways with a very simple Blink like sketch.

This is the code :-

// Simple test code for motor
//
const int MotorInAPin = 33; // Motor In A
const int MotorInBPin = 32; // Motor In B
void setup() {
pinMode(MotorInAPin, OUTPUT);
pinMode(MotorInBPin, OUTPUT);
}
void loop() {
digitalWrite(MotorInAPin, LOW); // Stop
digitalWrite(MotorInBPin, LOW);
delay(10000); // wait for 10 seconds
digitalWrite(MotorInAPin, HIGH); // Forward
digitalWrite(MotorInBPin, LOW);
delay(10000); // wait for 10 seconds
digitalWrite(MotorInAPin, LOW); // Reverse
digitalWrite(MotorInBPin, HIGH);
delay(10000); // wait for 10 seconds
}

Link to comment
Share on other sites

Further testing and got to next stage - using the push buttons on the control box which now work.  Made the code more modular for readability  Can't seem to post the code directly here so here's a link to my web space where I've saved it.  You may need to click on OK in the box that pops up to see it.

http://ginad.uk/RORautomation/Simple_test_code_for_motor_2_buttons.ino

Link to comment
Share on other sites

Added more code and done more testing.  Have the MQTT messages controlling the motor and status messages coming back.  The motor runs forwards and backwards under remote control and stops when commanded.  These functions also work from the push buttons on the control box and again the status is fed back,  The timeout function also works - once the time reaches 180s (as set currently) the motor stops and a message of "fault-timeout" is sent back to base.  To further check on the operation, the elapsed time since starting the motor is sent back to base as number of seconds and displayed in the Dashboard with the "Status".  There is also a representation of the motor current relayed back to base. 

Some of the features weren't working correctly and the code needed altering but now all tested features are working fine.  So far I haven't tested the operation of the limit switches and that will be the next test.

This is the Dashboard display :-

2001074762_Screenshotfrom2020-10-2921-06-06.png.aa4a178fb1d2bbca62a26b3b25ec2c25.png

Here's a link ti the sketch converted to text :- http://ginad.uk/RORautomation/MQTT_ROR_Automation_2020-10-29T21-00.txt

  • Like 1
Link to comment
Share on other sites

Connected wires to a connector so that I could test the rain sensor and limit switch inputs.  Decided to check the rain sensor input before enabling the limit switch code and that worked fine.  Now to test the limit switch action.

  • Like 1
Link to comment
Share on other sites

I have one of the limit switches stopping the motor but there seems to be interaction between the sensing in that one limit switch input stops both directions of motion and the other does nothing,  I have searched through the code trying to find the problem without success.  There is either a coding fault or I have my logic wrong.  No doubt it's something simple and probably silly - that's the usual case.  I'll produce a flow-chart and see if anything shows up.

Link to comment
Share on other sites

Flowcharts work well for logic but less well for program sequences.  I'm wondering if a different approach to coding this system may be better.  Rather than a sequence, perhaps logic to determine whether the motor should be turning one way or the other or stopped.  The main program loop could be running continuously, testing the various conditions.  If the loop repeat rate were a fraction of a second the response would be fast enough and no interrupts would be required.  Flags could be set by the inputs and cleared by limit reached or by the emergency stop control.

Two flags would be required OPEN and CLOSE.  These flags would be set by the local push buttons or the remote commands, plus the RAIN SENSED condition would set the CLOSE flag.  Either the STOP button or remote command would clear both flags.  The CLOSED limit switch would prevent the motor being told to CLOSE the roof and likewise the OPEN limit switch would stop the motor OPENING the roof.

Link to comment
Share on other sites

Realised that the flowchart didn't cater for fault conditions like timeout or motor being overloaded by an obstruction.  I can add these later though and get the processes in the flowchart working first,

Link to comment
Share on other sites

I am going to take the testing in stages as I am employing totally different logic.
    1. Test motor control only.
    2. Add limit switches to stop motor when limit reached.
    3. Add the detection of fault conditions.
    4. Add feedback back to base via MQTT messages.

Here is a screenshot of the code for stage 1. less most of the MQTT system which is already proved.  It can be seen that this new method produces far more compact code.  I've edited this post as the previous code wasn't working,  This code is now tested and working. (Click on image to enlarge)

RORControlCode.thumb.png.d9c7c76efa9c94e34d0a02b0b3d4396c.png

 

  • Like 1
Link to comment
Share on other sites

I'm having a problem getting the limit switches working ATM so I might leave that for now and move on.  Next easiest is the timeout, though adding the feedback by MQTT messages is pretty easy.

Link to comment
Share on other sites

Decided to add the status messages back in so that I can get a better idea of what's happening.  As a result I have found my error!!  Reading the pin number rather than the logic level.

There are two contact pairs on each limit switch one opening and one closing when the limit is reached. The closing pair connect to a light (LED) in the control box to show the roof is either fully closed or fully open. The other pair connect to the control board (ESP32) to tell the logic.

Logic contacts are open at limits - otherwise CLOSED. Motor should open roof if open limit is not reached ie, closed. Closed contacts mean pin is grounded ie. LOW. Thus roof should open if command=OPEN and logic on OpenLimitPin is LOW.

The limit switches are now working.

Here's a screenshot of the relevant piece of code.  Click to enlarge.

636841725_Screenshotfrom2020-11-0217-38-46.thumb.png.831a454837686e4f0a60dc6e0fa70355.png
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...