Home / APT_V2_HW
APT 2.0 Hardware & Interfacing

The bits of the APT we are concerned with are interfacing with the stepper motor controllers, Photomultiplier counters, handbox and user, we will control these using two Arduino boards, these present themselves to the Raspberry Pi as serial interfaces, so we will be creating a command structure to send and receive command/data between these devices.

Basic communication between the Raspberry Pi (RPi) and Arduino


All commands start with ^ and end with $. Commands from the RPi are 5 characters in length any parameters immediately follow the command, integers are always in the format 0nnnn when positive and -nnnn when negative.
The Arduino will return ^OK: plus the command it has confirmed to receive, plus $. If the Arduino can't understand a command it will return
^ERROR:XXXXX error message$ where XXXXX is the command that was given.

e.g.
RPi -> Ard ^INTDU+0030$
Ard -> RPi ^OK:INTDU$

where the command expects a result to the command it returns this directly after the command string terminating with the $
e.g.
RPi -> Arduino ^CREGI$
RPi <- Arduino ^OK:CREGI16777216$

Cardinal Points

East and South will be denoted by negative numbers
West and North will be denoted by Positive numbers

HAND BOX ARDUINO COMMANDS
Command
x Definition
Description



Display Commands
LCDCL

Clears LCD display
RPi->HB ^LCDCL$
HB->RPi ^OK:LCDCL$
LCDWTx or LCDL0x
x is 1 to 16 ASCII characters
Write upto 16 characters to the top line of the LCD display
RPi->HB ^LCDWTHello World!$
HB->RPi ^OK:LCDWT$
LCDWBx or LCDL1x
x is 1 to 16 ASCII characters
Write upto 16 characters to the bottom line of the LCD display
RPi->HB ^LCDWBHello World!$
HB->RPi ^OK:LCDWB$
TRANSx
x is 1 to 6 ASCII characters
Provide ASCII characters to be translated. Order: Up, Right, Down, Left arrows, Degree and Block
RPi->HB ^TRANSABCDEF$
HB->RPi ^OK:LCDWB$.
From now on, A will be displayed as an Up arrow, B as Right, C as Down, D as Left, E as Degree and F as Block
TROFF

Turn off the character translation
RPi->HB ^TROFF$
HB->RPi ^OK:TROFF$



Keypad Commands
KEYDN

Returns the key that is currently being pressed, "~" is returned for no key
RPi->HB ^KEYDN$
HB->RPi ^OK:KEYDNx$ (x is one of "01234567890ABCD*#~")
KEYED

Returns the last key that was pressed and released, "~" is returned for no key
RPi->HB ^KEYED$
HB->RPi ^OK:KEYEDx$ (x is one of "01234567890ABCD*#~")
KEYWT

Will wait for a key to be released before returning the key, cancelled if another command is received
RPi->HB ^KEYWT$
HB->RPi ^OK:KEYWTx$ (x is one of "01234567890ABCD*#")
KYCLR

Clears the last key pressed and released
RPi->HB ^KYCLR$
HB->RPi ^OK:KYCLR$
KALRT

Will wait for a key to be pressed then return that key, cancelled if another command is received
HB->RPi ^OK:KEYDNx$ (x is one of "01234567890ABCD*#~")



Miscellanous Commands
WHORU

Returns HB, i.e. I'm the HAND BOX Arduino
RPi->HB ^WHORU$ Which Arduino are you?
HB->RPi ^OK:WHORUHB$ OK, I am the Hand Box
VERSN

Returns the current version of the Hand Box Arduino firmware
RPi->HB ^VERSN$
HB->RPi ^OK:VERSNAPT HB V2.130504$
BUZZx
x is 1, 2 or 3
Makes one of 3 sounds through the handbox's buzzer
RPi->HB ^BUZZ1$
HB->RPi ^OK:BUZZ1$

PMT/DRIVE ARDUINO COMMANDS
Command
x Range
Description
Power Commands
APTON

Turns on the 240v power to the PMT power supply and the stepper motor power supply
RPi->PD ^APTON$
PD->RPi ^OK:APTON$
APTOF

Turns off the 240v power to the PMT power supply and the stepper motor power supply
RPi->PD ^APTOF$
PD->RPi ^OK:APTOF$



Drive Interrupt Commands
IRATEx or INTERx
245 to 900
Drive interrupt rate in ticks per second, probably 400
RPi->PD ^IRATE400$
PD->RPi ^OK:IRATE$
SRATEx
1 to 32767
Sidereal Rate in drive interrupt ticks, probably 40 (i.e.10hz)
RPi->PD ^SRATE40$
PD->RPi ^OK:SRATE$
RRATEx
1 to 32767
Right Ascension slew rate in drive interrupt ticks, probably starting with 10
RPi->PD ^RRATE10$
PD->RPi ^OK:RRATE$
DRATEx
1 to 32767
Declination slew rate in drive interrupt ticks, probably starting with 10
RPi->PD ^DRATE10$
PD->RPi ^OK:DRATE$
ISTOP or SSTOP

Stops the drive interrupt and hence stops the telescopes drives
RPi->PD ^ISTOP$
PD->RPi ^OK:ISTOP$
ISTRT or START

Starts the drive interrupt but only if sidereal, RA and DEC rates have been set
RPi->PD ^ISTRT$
PD->RPi ^OK:ISTRT$
IPRES
1, 8, 64, 256 or 1024
Sets the Arduino's TIMER1 interrupt prescaler for the telescope drive. 1 is the default, other values slow down the interrupt frequency by that amount. Used to test pulses to the test LEDs and stepper motor control boards.
RPi->PD ^IPRES64$ Slow the drive interrupt rate of, say, 400 hz by a factor of 64
PD->RPi ^OK:IPRES$ OK, the interrupt rate is now 6.25hz



Slewing Commands
RSLEWx or STEPRx
-32768 to 32767
Slews the telescope in RA by number of given steps (>0 East to West, <0 West to East)
RPi->PD ^RSLEW60$ Slew the telescope 60 steps from East to West
PD->RPi ^OK:RSLEW$ OK, I will start the slewing 60 steps in RA from East to West
DSLEWx of STEPDx
-32768 to 32767
Slews the telescope in DEC by number of given steps (> 0 South to North, < 0 North to South)
RPi->PD ^DSLEW-60$ Slew the telescope 60 steps from North to South
PD->RPi ^OK:DSLEW$ OK, I will start slewing 60 steps in RA from North to South
ARIVE

Returns the number of slew steps remaining (higher of RA and DEC slew steps remaining)
RPi->PD ^ARIVE$ How many steps are there to go before the telescope stops slewing?
PD->RPi ^OK:ARIVE00000041$ OK, there are still 41 steps to go
RSTOP

Stops the telescope slewing in RA and return the number of steps still to go (>0 E to W, <0 W to E)
RPi->PD ^RSTOP$ Stop slewing in RA
PD->RPi ^OK:RSTOP00000041$ OK, there are 41 steps left to slew East to West
DSTOP

Stops the telescope slewing in DEC and return the number of steps still to go (>0 S to N, <0 N to S)
RPi->PD ^RSTOP$ Stop slewing in DEC
PD->RPi ^OK:RSTOP-0000037$ OK, there are 37 steps left to slew North to South



PMT Commands
PTIMEx or INTDUx
1 to 1000000
Sets the PMT integration time in milliseconds for all future integrations
RPi->PD ^PTIME1500$ Set the integration time to 1.5 seconds
PD->RPi ^OK:PTIME$ OK. all future integrations will be 1.5 seconds
PMTGO or ISTART

Reset the counters and starts PMT integration
RPi->PD ^PMTGO$ Start integration for the period defined by PTIME/INTDU
PD->RPi ^OK:PMTGO$ OK, integration has started
PSTOP or ISTOP

Stops PMT integration prematurely
RPi->PD ^PSTOP$
PD->RPi ^OK:PSTOP$
PDONE or ICOMP

Is integration complete? Returns 1 = yes, 0 if no
RPi->PD ^PDONE$
PD->RPi ^OK:PDONE00000001$
PTIMR or ITIMR

Returns integration time remaining in milliseconds
RPi->PD ^IRATE$ How much integration time is there remaining?
PD->RPi ^OK:IRATE00001178$ OK, there is 1.178 seconds to go
PREGI or CREGI

Moves value of the Counters to the Registers and returns it (0 to 16777215) at any time
RPi->PD ^PREGI$ What is the current PMT counter value?
PD->RPi ^OK:PREGI16777215$ OK, it is 16777215
PTEST or CKENL

Activates CCKEN pins of the Counters and allow them to count indefinitely. PSTOP will deactivate them
RPi->PD ^PTEST$ Start count PMT pulse indefinitely
PD->RPi ^OK:PTEST$ OK, counters have started
RESET

Resets the Counters and Registers to a value of 0
RPi->PD ^RESET$
PD->RPi ^OK:RESET$



Miscellaneous Commands
WHORU

Returns PD, i.e. I'm the PMT/Drive Arduino
RPi->PD ^WHORU$ Which Arduino are you?
PD->RPi ^OK:WHORUPD$ OK, I am the PMT/Drive Arduino
VERSN

Returns the current version of the PMT/DRIVE Arduino firmware
RPi->PD ^VERSN$
PD->RPi ^OK:VERSNAPT PD V2.130626$
APTGO

Starts the APT drives by executing ^IRATE400$, ^SRATE40$, ^RRATE10$ and ^DRATE10$
RPi->PD ^APTGO$ Start the telescope drives in default mode
PD->RPi ^OK:APTGO$ OK, telescopes drives have now started
WAIT#x
1 - 100000
Inserts a delay in in milliseconds - useful when issuing a string of commands
RPi->PD ^WAIT#2000$ Wait 2 seconds
PD->RPi ^OK:APTGO$ OK, have waited 2 seconds (this confirmation response is sent only after the delay has expired - all later commands will now be processed)



Test Commands
TEST1

Turns on the test mode and gives the user access to these test commands and pin test commands
RPi->PD ^TEST1$
PD->RPi ^OK:TEST1$
TEST0

Turns off the test mode
RPi->PD ^TEST0$
PD->RPi ^OK:TEST0$
NLON#

Sends an ASCII 13 and 10 (carriage return & linefeed character) after each command response given
RPi->PD ^NLON#$
PD->RPi ^OK:NLON#$
NLOFF

Stops send ASCII 13 and 10 characters after each command response given
RPi->PD ^NLOFF400$
PD->RPi ^OK:NLOFF$
LINES

Returns the current value of each stepper line in the form of "Step x Dir x RA x Dec x" (x = 0 or 1)
RPi->PD ^LINES400$
PD->RPi ^OK:LINESStep 1 Dir 1 RA 0 Dec 0 $
MEMRY

Returns the PD Arduino's free RAM
RPi->PD ^MEMRY$
PD->RPi ^OK:MEMRY00000785$
BUS##

Returns the value of the Counters' data bus in an 8 bit binary number
RPi->PD ^BUS##$
PD->RPi ^OK:IRATE01101010$
LEDS#

Flashes each test LED in turn for 5 seconds, STEPpin, DIRpin, RAPULSEpin & DECPULSEpin
RPi->PD ^LEDS#$
PD->RPI ^OK:LEDS#$
VARS#

Returns the value of certain variables
RPi->PD ^VARS#$
PD->RPi:
pmt_duration 00000000
pmt_timer 00000000
drvISRrate 00000000
ra_rate 00000000
ra_tix 00000000
ra_steps 00000000
dec_rate 00000000
dec_tix 00000000
dec_steps 00000000
sid_rate 00000000
sid_tix 00000000
^OK:IRATE$



Pin Test Commands


'x' tells the PD Arduino what action to take on a selected pin:
H = set pin to HIGH (1)
L = set pin to LOW (0)
R = read pin, returns H or L
I = inverts current value of pin (L to H, or L to H)
F = flip flops the current value of pin (L to H to L, or H to L to H)
CCLRx

Carries out action x on the Counters /CCLR pin
RPi->PD ^CCLRH$
PD->RPi ^OK:CCLRH$
CKENx

Carries out action x on the Counters /CCKEN pin
RPi->PD ^CKENL$
PD->RPi ^OK:CKENL$
RCK#x

Carries out action x on the Counters RCK pin
RPi->PD ^RCK##R$ What is the value of the pin connected to the Counters' RCK pin?
PD->RPi ^OK:RCK##RH$ OK, the value of the pin is H (HIGH, 1)
G1##x

Carries out action x on the Counter 1 /G pin
RPi->PD ^G1##I$
PD->RPi ^OK:G1##I$
G2##x

Carries out action x on the Counter 2 /G pin
RPi->PD ^G2##F$
PD->RPi ^OK:G2##F$
G3##x

Carries out action x on the Counter 3 /G pin
RPi->PD ^G3##H$
PD->RPi ^OK:G3##H$
RA##x

Carries out action x on the stepper RAPULSE line (trigger = 1 to 0)
RPi->PD ^RA##L$
PD->RPi ^OK:RA##L$
DEC#x

Carries out action x on the stepper DECPULSE line (trigger = 1 to 0)
RPi->PD ^DEC#R$
PD->RPi ^OK:DEC#RH$
DIR#x

Carries out action x on the stepper DIR line (direction) (0 = RA W to E, DEC S to N, 1 = RA E to W, DEC N to S)
RPi->PD ^DIR#I$
PD->RPi ^OK:DIR#I$
STP#x

Carries out action x on the stepper STEP line (step type) (0 = full step, 1 = half step)
RPi->PD ^STP#F$
PD->RPi ^OK:STP#F$


(DIR and STEP lines are both tied to the RA and DEC stepper motor control boards)


Managing Communication Errors

The RPi software will always expect a response from the Arduino in the form of ^OK:command$ where command is the original command sent, if it doesn't receive this it will re-send the command, it will do this up to 5 times before giving up and gracefully exiting the program providing the user with feedback on what failed to send.

Test Software

This is a very simple python program that scans the available serial ports and identifies the one with the Arduino connected

This program scans the available serial ports for the hand box its main purpose is to test the LCD and keyboard are working and to prove python code can read the key presses and write to the LCD and that the keyboard can be acted on very quickly.

The software will work on any OS (tested on linux and windows)

Schematics

Here is the schematic for the Arduino shield for connection to the Photo Multiplier Tube and the Stepper Motor Control Boards.

APTv2 Software

There is a separate page for software




Copyright © 2005-2017 Crayford Manor House Astronomical Society Dartford, Kent.Registered Charity Number 1156678. All rights reserved. No part of this website may be reproduced.
Page edited 107 times. Last edit by - kickitharder kickitharder on Nov 26, 2013 5:27 am. This site contains 560 pages
CMHASD - APT_V2_HW