element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
CodeBug
  • Learn
  • Learning Center
  • STEM Academy
  • CodeBug
  • More
  • Cancel
CodeBug
Blog 10 CodeBug Projects in 10 Days: CodeBug and Raspberry Pi Clock
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join CodeBug to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: element14Dave
  • Date Created: 23 Sep 2015 8:25 PM Date Created
  • Views 1235 views
  • Likes 20 likes
  • Comments 3 comments
  • codebug_advanced
Related
Recommended

10 CodeBug Projects in 10 Days: CodeBug and Raspberry Pi Clock

element14Dave
element14Dave
23 Sep 2015
imageIntroducing CodeBug!

image  What is CodeBug

image  10 CodeBug Projects in 10 Days

image  Are You a STEM Educator?

 


This project will build off of the Teathering CodeBug with Python and Raspberry Pi Controlled CodeBug with I2C projects. Rather than taking advantage of the Blockly interface and emulation plug in on http://www.codebug.co.uk. we'll be bringing some Python code into the mix.


Follow the steps below to get started on this advanced project Thomas Macpherson-Pope pulled together from CodeBug.org.uk

 


What you need:

CodeBug

Micro USB Cable

Raspberry Pi2

Computer

image

 


The Project


Before we get started on this project we will need to make sure we have followed the 10 CodeBug Projects in 10 Days: Raspberry Pi Controlled CodeBug with I2C project.  We'll also need to make sure to have the CodeBug connected in the correct position on the Raspberry Pi's GPIO before attempting this project.


NEVER connect the Micro USB or use a battery with CodeBug while it is fitted to a Raspberry Pi.



We can create some amazing projects, by controlling the CodeBug with Python using the Raspberry Pi’s I2C port.

This guide will walk through how to create a scrolling digital CodeBug clock.


Your Python program needs to get the time and date from the Raspberry Pi and scroll it on CodeBug’s display.

Open a Terminal and start a new Python program by typing:

nano ~/codebug_i2c_clock.py

Enter the following code into the file and save it:

import codebug_i2c_tether  import datetime  import time  # make a connection with CodeBug  cb = codebug_i2c_tether.CodeBug() cb.open()  # function for scrolling messages on CodeBug’s display  def scroll_message(message):  length = len(message)  for i in range(0,length*-5,-1): cb.write_text(i, 0, message, direction="right") time.sleep(.15)  while True:  # get the time and scroll it  time_str = datetime.datetime.now().strftime("%H:%M:%S") scroll_message(" Time " + time_str)  # get the date and scroll it  date_str = datetime.datetime.now().strftime("%d/%m/%Y") scroll_message(" Date " + date_str)

Next, lets test the clock by entering the following command into a Terminal:

python3 ~/codebug_i2c_clock.py

Exit the program by pressing Ctrl C.

If  the CodeBug is displaying the wrong time, we'll need to change the timezone on the Raspberry Pi or update the time by being connected to the Internet. To change the timezone we can  open a terminal and type:

sudo raspi-config

Using the arrow keys to navigate through the list and select Internationalization Options then select Change Timezone and select the region and closest large city.


We can run the clock automatically whenever we turn on the Raspberry Pi (even without logging in)!

To do this we'll need to edit a system file with this command:

sudo nano /etc/rc.local

Enter the following line directly above exit 0 line:

python3 /home/pi/codebug_i2c_clock.py &

Now restart the Raspberry Pi and the clock will begin to run before you log in.

When we want the clock to stop running we can do so by typing:

ps aux

Next, we'll find the process that has python3 /home/pi/codebug_i2c_clock.py in the end column, and take a note of its process id (from the second column). Let's run:

sudo kill -9 your-process-id

e.g:

sudo kill -9 2887

If we want to remove the clock,  we can simply edit the rc.local file and remove the line we just inserted:

sudo nano /etc/rc.local


Now that the clock is set up, let's think about other ways to program the clock. How about an alarm clock? Weather report? Let us know how you would apply this project!

 


See more CodeBug projects and learn how you can get one of your own by visiting: 10 CodeBug Projects in 10 Days

  • Sign in to reply

Top Comments

  • Former Member
    Former Member over 9 years ago +6
    I have seen a few Raspberry Pi servers used to host blogs. This could be combined with one so that the code bug has a happy face when the server is up, a sad face when it is down, and an excited face when…
  • alienozi
    alienozi over 9 years ago +2
    A potencial use may be a clock for kids who spend a lot time on a compter. When your timer on raspberry pi times up, Code Bug would make a annoying noise and also a facial expression (maybe angry or sad…
  • alienozi
    alienozi over 9 years ago

    A potencial use may be a clock for kids who spend a lot time on a compter. When your timer on raspberry pi times up, Code Bug would make a annoying noise and also a facial expression (maybe angry or sad?).

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    Nice, thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    I have seen a few Raspberry Pi servers used to host blogs. This could be combined with one so that the code bug has a happy face when the server is up, a sad face when it is down, and an excited face when you get a new comment.

    • Cancel
    • Vote Up +6 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube