About a year ago I got a Pimoroni Scroll pHat for a school project. Its a small LED display form a RPi zero. It’s been sitting around for a few months so I thought I’d stretch my frankly appalling coding skills and turn it into a display for upcomming observations. It sort of works although there are bits that could be better but I’ve run out of time again and will share this half finished bit of fun in the hopes that someone else might find it a nice evening project.
The backbone is a rpi zero running Raspbian stretch lite. The scrollphat libraries have been imported and short python script looks in the API and pulls out the data for my ground station and scrolls it across the screen. The code is below. For the avoidance of doubt I don’t normally write code
#!/usr/bin/env python3
import urllib.parse
import requests
import scrollphathd
import time
from datetime import datetime
#Define the URL for the specific ground station. In this case ground station 33 (G7KSE VHF)
obs_url = 'https://network.satnogs.org/api/jobs/?id=&ground_station=33&satellite__norad_cat_id=&transmitter=&vetted_status=&vetted_user=&star$
# p.s. this is the base url obs_url = 'https://network.satnogs.org/api/jobs/?format=json'
#sort out what is needed from API and define the variables
json_data = requests.get(obs_url).json()
observation_data = json_data[0]
obs_id = observation_data['id']
start = observation_data['start']
sat = observation_data['tle0']
tx = observation_data['mode']
#Convert JSON date & time into useable string
date_time_obj = datetime.strptime(start, '%Y-%m-%dT%H:%M:%SZ')
date = date_time_obj.strftime("%d %b")
obtime = date_time_obj.strftime("%H:%M")
#rotate the scrollphat 180 degrees and set brightness
scrollphathd.rotate(degrees=180)
scrollphathd.set_brightness(0.5)
#print out the data
scrollphathd.write_string("...Next up: " + date + " " + obtime + " " + sat + " " + tx + ".....")
# should really eplace this with an if/else in case nothing is scheduled
# then print using scrollphathd.write_string("...Nothing scheduled...."
# Auto scroll using a while + time mechanism (no thread)
while True:
# Show the buffer
scrollphathd.show()
# Scroll the buffer content
scrollphathd.scroll()
# Wait for 0.1s
time.sleep(0.05)
Don’t have a gitlab login yet (I’ll make one tomorrow), but I was modifying this code just to run in the terminal as I don’t have a display, yet.
Code works great, but I noticed that the api doesn’t seem to work when I put my “272” station in the url. The request thus fails. If I change the api url to “187”, it pulls in the data just fine. Weird.
Morning @K3RLD . I originally had a play with the code on a website called repl.it . I ended up with this:
import urllib.parse
import requests
from datetime import datetime
#Define the URL for the specific ground station. In this case ground station 33 (G7KSE VHF)
obs_url = 'https://network.satnogs.org/api/jobs/?id=&ground_station=33&satellite__norad_cat_id=&transmitter=&vetted_status=&vetted_user=&start=&end='
#sort out what is needed from API and define the variables
json_data = requests.get(obs_url).json()
observation_data = json_data[0]
obs_id = observation_data['id']
start = observation_data['start']
sat = observation_data['tle0']
tx = observation_data['mode']
#Convert JSON date & time into useable string
date_time_obj = datetime.strptime(start, '%Y-%m-%dT%H:%M:%SZ')
date = date_time_obj.strftime("%d %b")
#print out the data
print('Next Obs is' , obs_id , 'at', date_time_obj.time(), 'On the', date)
print('Sat:', sat , '....' , 'Mode:' ,tx)
There are quite a few shortcomings as I see them. Firstly, and I think this might apply in your case, when there are no observations scheduled then it doesn’t know what to do. So there ought to be a statement that prints ‘No obs today’ if there is nothing there. The second one I can see is that it doesn’t check back once the next observation has been completed. I suppose a cron job could check every few minutes but it didn’t seem like a sensible thing to me.
No doubt there will be more ‘iffy’ things in there but as I’m no code kid it took me a long time to work even the basic stuff out. I think I could do with a bit of a point in the right direction for the more elegant stuff, for now I’ll keep looking in various docs and posts to see what I can find in my spare time
Never thought of the “zero jobs” situation. I did notice that the code as shown in your first post seems to display the last job returned, rather than the “next up”. So I just added a line to count the items in the list and and then rather than display list item “0”, I display the “sum - 1”. I imagine a few lines that use the timing of the passes shown could force the code to move to the next observation and eventually renew the json data.
I haven’t gotten that far. I’m going to order the display and a new pi soon, at which point I start contributing to the git - for now my code uses just the terminal so no point in “dumbing” down the existing code. This is a fun learning project for me, as I’ve already utilized info from the first few chapters of the python book I purchased (“Python Crash Course” by Eric Matthes, in case anybody is interested).
That’s all it was for me Roy, I’d been given a python book and found it a bit dry so that’s why I had a go at this. There have been many iterations
The json(0) bit was what I was using for picking the next obs as that’s what it looked like when I looks at the api data on a web browser. I guess there is a more elegant way so feel free to mod in any way you want.
Just as an aside I looked at node red as well, as it was on a RPi and got quite close to doing the same thing with a web page, the idea for this one was to use an old kindle I was given and have that as an epaper display, So far that is not working as well. Good to have a go though.
Heh, finally got the scroll phat - couldn’t get the code to work.
Figured it out for myself, though - I bought a “scroll phat”, and the code is for the “scroll phat HD”. Whoops! A few quick command changes and it works perfectly, though - with just a little bit less resolution! I’m going to have some fun with this!
I didn’t know they were still selling the non HD one. I can’t really tell if the end result will be better or worse (there are definitely not 1080 leds)