Joachim Kristensen
Published © GPL3+

Den Gode Dag/The Good Day

Did real time coding at a conference called "Den Gode Dag" / "The Good Day". The purpose of the day was to promote good news via data.

BeginnerShowcase (no instructions)2 hours740
Den Gode Dag/The Good Day

Things used in this project

Hardware components

SiPy
Pycom SiPy
×1
TextStar Serial LCD Display
×1
Arcade button
×1

Software apps and online services

Pymakr Plugin
Pycom Pymakr Plugin
Sigfox
Sigfox
Sublime Text 2
FileZilla

Story

Read more

Code

Main.py for the project

MicroPython
import pycom
import time
from machine import Pin, UART
import micropython
import textstar

#Start by turning of heartbeat
pycom.heartbeat(False)

#Set a start color
pycom.rgbled(0x007f00)


# UART_1 default pins for TXD (''P3'') RXD (''P4'')
uart = UART(1, baudrate=9600)

#Configure the two buttons as inputs
p_green = Pin('G22', mode=Pin.IN, pull=Pin.PULL_UP)
p_blue = Pin('G28', mode=Pin.IN, pull=Pin.PULL_UP)

#The list of news in a dict
goodNews = {'1': 'Kaempe fald i kulkraft',
 '2': 'Middelklassen vinder frem',
 '3': 'DK App beskytter skov',
 '4': 'Afrika bygger groen mur',
 '5': 'Baeredygtig fiskeri i Kenya'}

#Start by clearing the display of anything
textstar.TEXTSTAR(uart, 'clearDisplay')

#Variable for saving which number the current news has
newsNumber = 0

#Finding a random news from the list and displaying it
def randomNews():
	textstar.TEXTSTAR(uart, 'clearDisplay')
	textNumber = randomNumber()
	textNumber = str(textNumber)
	textstar.TEXTSTAR(uart, goodNews[textNumber])
	return textNumber

#Getting a random number
def randomNumber():
	number = (machine.rng()/(2 ** 30 - 1)) * 1000
	if number <= 3:
		return(1)
	elif (number <= 6) and (number >= 3):
		return(2)
	elif (number <= 9) and (number >= 6):
		return(3)
	elif (number <= 12) and (number >= 9):
		return(4)
	elif number >= 12:
		return(5)

#For the first text on the display before the loop begins. 
text = randomNews()

while True:
	if p_green() == False:
		#Begin by changing color
		pycom.rgbled(0x7f7f00)
		#Send the information to SigFox
		s.send('We like '+str(newsNumber))
		#Print to REPL
		print(newsNumber)
		#Set the next news for the display
		newsNumber = randomNews()
		#Print the choice
		print('Green')
		#Turn color back to "ready"
		pycom.rgbled(0x007f00)
	elif p_blue() == False:
		pycom.rgbled(0x7f0000)
		s.send(str(newsNumber)+' is nah')
		print(newsNumber)
		newsNumber = randomNews()
		pycom.rgbled(0x007f00)
		print('Blue')

Textstar Serial LCD Display driver for Pycom

MicroPython
Initialize uart in the main.py
Send uart and your text to the driver for it to be display.
If the text reads clearDisplay, the display will be cleared
### Textstar display ###
### Inspired by http://jeremyblythe.blogspot.dk/2012/07/raspberry-pi-with-textstar-serial-lcd.html ###
### Written by Joachim Kristensen 2017 ###

#Adresse for clearing display
CLEARDISPLAY = chr(12)


class TEXTSTAR:
	def __init__(self, uart, text):
		self.uart = uart
		self.text = text
		if self.text == 'clearDisplay':
			self.uart.write(CLEARDISPLAY)
		else:
			self.writeText(self.text)

	def writeText(self, text):
		self.uart.write(text)

Credits

Joachim Kristensen

Joachim Kristensen

1 project • 3 followers

Comments