Writing to Inkyphat


#1

Hi all,

New to this site but have had great fun playing with the inkyphat since it arrived. Working on adapting some code to turn my phat into a bus departure board.

Everything works fine except I’m getting a syntax error here and I can’t work out why. Have I phrased this correctly for the phat? I can’t see any examples of using a for loop to change drawing position for each line so took a guess that’s allowed :)

draw.text ((1, ix34-33) ((bus[‘bus’], dest), inky_display.BLACK, font=font)
draw.text ((160, ix
34-33) (disptime), inky_display.BLACK, font=font)

Full code here


Appreciate any advice on this one. Thanks so much.


Tiny OLED Bus Timetable from a Web Scrape (not an API)
#2

I’ll look over your code in the GitHub repo and see what’s up!

Edit: - couple of things.

draw.text ((1, ix*34-33)  ((bus['bus'], dest), inky_display.BLACK, font=font)
draw.text ((160, ix*34-33) (disptime), inky_display.BLACK, font=font)
  • First, you’re missing a comma right after the postion tuple, and
  • Second, you need to use the same "string".format(value)" technique as you use earlier in your code to make sure what you’re trying to display on the Inky pHAT is a properly formatted string.

So your code should look (and bear in mind I haven’t actually tested this), something like this:

draw.text ((1, ix*34-33), "Bus: {} Dest: {}".format(bus['bus'], dest), inky_display.BLACK, font=font)
draw.text ((160, ix*34-33), disptime, inky_display.BLACK, font=font)

For future reference, you should surround your code with backticks, or use the litle code icon in the editor so it doesn’t treat syntax as formatting:

```
like so
```

#3

Thanks gadgetoid, works perfectly now. Have uploaded changes to GitHub if anyone wants their own. Might post this to projects when it has a nice frame.

Very satisfying to get it working!


#4

No worries! Glad you’re up and running.


#5

OK, you’ve inspired me.

Down here outside of London we don’t get fancy api’s.

So, here is a quick BeautifulSoup gist that will scrape my local bus website and tell me when the next horseless carriage will be passing to convey me towards town.

from bs4 import BeautifulSoup
import requests

# Page url to scrape
page_url ='https://www.buses.co.uk/stops/149000006645'

# Fetch the content from url
page_response = requests.get(page_url, timeout=5)

# Parse html
page_content = BeautifulSoup(page_response.content, "html.parser")

# Extract the html element where the next time expected is stored
time_expected = page_content.find(class_='single-visit__time--expected')

# Strip extraneous html
next_bus = time_expected.text.strip()

# Output
print next_bus

I just need to get this into an Inky pHAT now !

Cheers,

Simon.