4. First Application: HelloWorld(Spark Mode)

Acoording to the coding tradition, here is our first program: HelloWorld
In this simple program we will be outputs "Hello World!" on the OLED screen while showing temperature of the current RPi-Spark pHAT, also draws an horizontal line.

  1. Create a file named: HelloWorld.py, and type the content below:
from JMRPiFoundations.Skeleton.RPiSparkModule import RPiSparkModule
class HelloWorld(RPiSparkModule):
     def setup(self):
         # Open thermometer sensor
         self.RPiSpark.Attitude.openWith(temp=True, accel=False, gyro=False)

     def run(self):
         # Show "Hello World !" and current temperature of RPi-Spark on screen of RPi-Spark
         text = "Hello World !\nTemp: {:6.2f}".format(self.RPiSpark.Attitude.getTemp())
         self.RPiSpark.Screen.write( text, xy=(0, 16), spacing=10, screenCenter=True )
         # Draw a 2 pixels width line
         self.RPiSpark.Screen.Canvas.line( (24, 32, 98, 32), 1, 2 )  
         self.RPiSpark.Screen.refresh()
  1. Save this file and execute the following command in the terminal:
$> rspk HelloWorld -f

And now you should see the result below:

HelloWorld

Isn't that easy? In our next lesson we will be introducing the easy development framework in RPi-Spark SDK


 

Was this article helpful?

YES     |     NO

 

Enjoying the project? Spotted a mistake? Any opinions on the website? Let us know!