Some projects don’t get abandoned. They just sit on a shelf, half-working, while you tell yourself you’ll get back to them next month. The ASCOM driver for the roll-off roof at Rumah Surya was one of those. I put it down about three years ago. This month I finally found the will, and the energy, to pick it up again.
I should say up front: I’m an astronomer, not an engineer. I have no training in electronics or programming. Everything here, from wiring relays to an Arduino to writing a Windows driver, I taught myself, mostly by reading, breaking things, and trying again. Nobody asked me to do it. I just enjoy it. So read what follows as notes from someone who learned on the job, not as the word of an expert.
What it does
The roof at Rumah Surya slides open and closed on a motor. An Arduino sits between the motor controller and the observing computer: it pulses relays to open, close, or stop the roof, and reads two analog lines that go high while the motor is turning in either direction. On the PC side, an ASCOM Dome driver lets software like N.I.N.A. treat the roof as a shutter, so a sequence can open it at dusk and close it again at the end of the night.
That was the idea, anyway. The first version worked well enough to demo, and not well enough to trust.
The roof we have
None of this would be so fussy if the building had been made for it. It wasn’t.
The roof was never designed to open and close automatically. Not long ago it had to be cranked open by hand, with a chain and pulley. The motor came later, fitted to a structure that was built for an arm and a handle, not for a computer.
The room is also too small for the telescope it holds. It was the only space left at the observatory, so the telescope went in anyway. The catch is that the roof can only move once the telescope is parked; anywhere else, the tube is in the way. Every open and close has to be preceded by a park, without exception.
Then there is the weather. The local climate means conditions at the observatory can swing from safe to unsafe quickly: a clear sky can turn to cloud or rain well before the forecast says it should. A system that waits for a person to notice and react will be too late some of the time. The automation has to be robust enough to close up on its own and get it right every time.
All of this matters more than usual because of what lives under that roof: the observatory’s first fully robotic telescope system. A robotic telescope is only as robotic as its roof. If the roof can’t be trusted to open when it should, close when it must, and always say where it is, nothing downstream can run unattended.
What was wrong with the old version
The original driver started from the standard ASCOM template back in 2021, and the firmware was written alongside it. A few things kept biting:
- The firmware blocked. Every relay pulse used
delay(), so for a couple of seconds after each command the Arduino couldn’t answer anything. A driver asking “are you moving?” at the wrong moment just got silence. - Status was guesswork. After a stop, the roof reported “error” no matter where it actually was. “Open” and “closed” came from remembering the last command, not from what the motor had done. A leftover debug print also slipped raw sensor numbers into the replies.
- Timing assumptions were too tight. The firmware gave the motor 60 seconds to finish. The roof sometimes needs longer than that.
- Only one program could talk to the roof. The driver was an in-process DLL, so whichever application loaded it owned the serial port. There was no way to check on the roof, or stop it, without going through that one application.
Alpaca or classic?
Before writing any new code, I spent longer than I’d like to admit going back and forth on one question: should the new driver be an ASCOM Alpaca device, or a classic COM driver like the old one?
Alpaca was tempting. It is where ASCOM is heading. It speaks plain HTTP, so the roof could be
controlled from any machine on the network, and from Linux, macOS, or a Raspberry Pi, not just
Windows. It would also have meant saying goodbye to COM registration, regasm, and the
administrator-rights puzzles that come with them. Starting over seemed like the right moment to
make the jump.
In the end I stayed with classic, for three reasons:
- Existing setups keep working. A classic driver could keep the old driver’s ID, so the N.I.N.A. profiles already pointing at “atapSurya” didn’t need touching.
- Everything lives on one Windows PC. The Arduino and the observing software sit on the same computer at Rumah Surya. Nothing needs to reach the roof over the network.
- It’s simpler. No HTTP server, no discovery, no firewall rules, and I could build on the C# I already had instead of learning a new stack at the same time as fixing the old one.
Rewriting everything at once was the very thing that had kept this project on the shelf. Picking the smaller step was what let me actually finish it.
I haven’t closed the door on Alpaca, though. The new program already owns the serial port and keeps all the roof logic in one place, so adding an Alpaca endpoint alongside the COM one later should be an addition, not another rewrite.
What changed
The firmware is now fully non-blocking. Relay pulses run as a small state machine in the main loop, so the Arduino answers every status request even while the roof is moving. It decides “open” or “closed” when the motor stops on its own at the end of travel, and it treats a stop halfway as what it is: a position it can’t vouch for. The last known state is saved to EEPROM, and anything saved mid-move comes back as “unknown”, so a power cut halfway through never pretends the roof is shut. Unlike the Paths of the Dead, this roof doesn’t get to declare “the way is shut” unless it really is. (That’s the warning at the Door of the Dead under the Dwimorberg, which Aragorn and the Grey Company pass on their way to the Paths of the Dead in The Return of the King.)
I timed the roof properly this time: closing takes about 68 seconds, and opening anywhere from 43 to
69. The motion timeout is now 100 seconds; if the motor is still turning after that, the firmware
stops it and reports an error. It also notices when someone moves the roof with the motor
controller’s own buttons or remote, instead of losing track. And there is a new SENSE# command
that returns the raw sensor readings, which makes diagnosing problems at the site much less of a
guessing game.
The driver side was rewritten as a standalone Windows program that is also an ASCOM local server. It is the only thing that opens the serial port, and everything else shares it: the program’s own window and any number of ASCOM clients at once. If it isn’t running when N.I.N.A. picks the driver, Windows starts it, and it waits in the system tray. From there you get:
- a control page with the roof’s state, estimated travel progress, Open / Close / STOP buttons, and a list of connected clients;
- a diagnostics page with live sensor values, a history of every roof trip, a filterable log, and a raw command console;
- a tray icon whose colour follows the roof’s state, with Open, Close, and Stop in its menu;
- a warning when you try to quit while the roof is still open or a client is still connected.
One rule I held to throughout: quitting the program, or a client disconnecting, never moves the roof. It stays exactly where it is.
The new driver keeps the same ASCOM ID as the old one, so existing N.I.N.A. profiles keep working. It also comes with a proper installer now, instead of a list of manual registration steps.
If you’re building one yourself
If you’re writing firmware and an ASCOM driver for your own roof or dome, here is what I wish I’d known the first time.
On the firmware side:
- Never block the loop. No
delay()once the motor is involved. Usemillis()and a small state machine, so the board can always answer, and can always be told to stop. - Make the hardware tell you the state. A remembered “last command” is not a position. Read limit switches or motor sensors, and decide “open” or “closed” from what actually happened.
- Be honest about “unknown”. If the roof stopped halfway, or the power went out mid-move, report an error state. A driver that says “closed” when it isn’t is worse than one that admits it doesn’t know.
- Measure your travel times before choosing timeouts. Time several real runs in both directions, then add a generous margin. Mine opened in anywhere from 43 to 69 seconds; a guessed 60-second limit was always going to fail.
- Set relay pins to their idle level before making them outputs, so nothing clicks on during boot.
- Keep the serial protocol small and strict. One command per line, one reply per command, and no stray debug prints in between. Add a diagnostic command that dumps raw sensor values; you will be glad of it at the site.
On the driver side:
- Decide early who owns the serial port. An in-process DLL ties the port to whichever program loaded it. A local server lets your own control window and several ASCOM clients share one connection.
- Poll status in the background and give every read a timeout. Treat a few missed replies in a row as a lost connection instead of hanging the client.
- Expect the board to reset when the port opens. Many Arduinos do. Wait for it, and use a simple handshake command to confirm it is really there before reporting “connected”.
- Never move the roof on exit or disconnect. Closing a program should not have side effects on hardware. Leave safety actions like “close on bad weather” to the sequencer or a safety monitor, where they are explicit.
- Always give people a way to stop it that doesn’t depend on the client software: a STOP button in your own window, a tray menu, and the motor controller’s own buttons.
- Run ASCOM Conform against your driver. It catches a surprising number of small mistakes in how properties and exceptions behave.
- Keep the same ASCOM ID when you rewrite, if you can, so existing profiles keep working.
And above all, test with a hand on the physical stop button. A roof that moves when you didn’t expect it, or doesn’t stop when you did, is a problem software can’t undo.
Next
It works on the bench and on the real roof. What’s left is the slow part: running it through real nights, letting a sequencer open and close the roof unattended, and seeing what breaks. I’ll write again once it has a few of those behind it.
It took three years to come back to this. The work itself took far less. I suspect most shelved projects are like that.