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: Teathering CodeBug with Python
  • 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:21 PM Date Created
  • Views 1324 views
  • Likes 20 likes
  • Comments 3 comments
  • codebug
  • codebug_advanced
  • iot
Related
Recommended

10 CodeBug Projects in 10 Days: Teathering CodeBug with Python

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 actually be a little different than our previous 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

Computer


The Project

This project will allow us to reach the full potential of your CodeBug with tethered mode. You can make programs that will be able to:

  • Respond and control Minecraft
  • Display Tweets on CodeBug
  • Control CodeBug from the web
  • Display alerts and the time on CodeBug
  • Create anything you can imagine in Python
  • Turn CodeBug into an Internet of Things device

 

To use CodeBug Tether you will need to load it with a special project file. Once this is done you can control CodeBug with Python over a USB connection.

For tethered mode you need to load your CodeBug with a special project file. This is done in the same way as a regular CodeBug program (refer to the download guide for details).

Download the CodeBug tether project file and load it onto your CodeBug.

image

Next, you need to install some Python modules.

You must now install the Python libraries that will talk to your CodeBug.

Open a Terminal window and type:

sudo apt-get update  sudo apt-get install python3-serial python3-codebug-tether

You can write your own tethered CodeBug programs using Python and a few simple commands to control your CodeBug. In the next steps you will start an interactive Python session and enter commands to interact with your tethered CodeBug. Don’t forget you need the tethered mode project installed on your CodeBug for them to work.

Open a Terminal and type:

sudo python3

You will see the python prompt appear >>> Now type:

import codebug_tether cb = codebug_tether.CodeBug() cb.set_pixel(2, 2, 1)

You will see the center LED - at position (2, 2) - light up on CodeBug.

NB: On some computers, or if you have multiple CodeBugs you will have to put the address of your CodeBug in brackets. More details are in the section Addressing Your CodeBug.

Now try setting a row of CodeBug’s LEDs at the same time:

cb.set_row(3, 0b10100)

You will see the third row of LEDs light up in the sequence you gave. 0b10101 is a binary value. The 0b shows that it is binary and the 10100 determines which bits (or LEDs in our case) are on. 1 represents on and 0represents off. This means that the LED to the far left is on (column 0), the next LED is off, the next on (column 2), and the final two LEDs are off.

Write text on the CodeBug’s LEDs, using the command:

cb.write_text(0, 0, "A")

image

An A will appear on the CodeBug LEDs.

Write scrolling text on CodeBug’s LEDs, using the commands

for i in range(0,-30,-1): cb.write_text(i, 0, 'Hello', direction="right")  time.sleep(.1)

The text "Hello" will be scrolled on CodeBug’s display.

Check whether a button is pressed, by giving get_input either an 'A' or a 'B':

cb.get_input('A')

This will return True if the button is pressed, otherwise it will return False.

Get a full list of the commands available by typing:

help(cb)

You can write longer programs for tethered mode CodeBug by writing commands in your text editor and then saving and running the file in the way you did with the examples earlier.

Tethered mode gives your CodeBug access to the full computing power, functionality and network connectivity of your computer! You can use variety of powerful yet easy to use Python modules allow your CodeBug to generate random numbers, react to emails or even respond to Twitter.

The CodeBug tether library has a default address for CodeBug. In most cases this will work, however if you have multiple CodeBugs connected you may need to change the address you’re using.

To do this, first open a Terminal and type the commands:

ls /dev/tty*

Plug the CodeBug back into your computer’s USB port and wait a couple of seconds. Then type the command:

ls /dev/tty*

See what address has been added to the list (you should see something like ttyACM0 for Raspberry Pi ortty.usbmodemfd141 for Mac). You may find it easier if you unplug your other USB devices first.

When you initiliase CodeBug in your Python programs, you must pass it the address you have found.

e.g.

cb = CodeBug(‘/dev/tty.usbmodemfa141’)

 

Now we are set to turn the CodeBug into an Internet of Things device!

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

  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 9 years ago +1
    Unfortunately the images seem to have been affected by the recent site issues I take it back F5 seemed to cure it ... element14Dave
  • mamvcivm
    mamvcivm over 9 years ago +1
    Hi there, Hope you can help. I've been trying to get the Codebug Tether to work on a PiZero. I have the serial and codebug-tether libraries installed - I can use commands such as codebug.set_row(3, 0b10100…
Parents
  • mcb1
    mcb1 over 9 years ago

    Unfortunately the images seem to have been affected by the recent site issues


    I take it back F5 seemed to cure it ...

     

    element14Dave

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • mcb1
    mcb1 over 9 years ago

    Unfortunately the images seem to have been affected by the recent site issues


    I take it back F5 seemed to cure it ...

     

    element14Dave

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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