1 First Steps in mpy Programming

Install the Software

First install the mpy Software, you won’t be able to do anything without downloading and installing the software.

To install the software follow the instructions here.

Example blinky.mpy

Lets start by programming a very simple mpy program blinky.mpy

(mpy programs end with .mpy )


################################################################
#  blinky.mpy    Flash the green led
################################################################

pindir(P1_6,OUT)    # Set pin P1_6 to be an output (this is connected to the Launchpad green led)
while 1:            # loop forever
   out(P1_6,1)      # turn the green led on
   wait(500)        # wait for 500ms  (half a second)
   out(P1_6,0)      # turn the green led off
   wait(500)

This is the same example mpy program that is used when you first install the mpyEditor software.  You may have already gone through this step but  it’s worth doing it again so that you get the hang of it. Follow these steps to program the microcontroller with this program.

Enter the Program and Program the Microcontroller

  1. Start the mpyEditor program by double clicking the mpyEditor icon    on the desktop (or you can select mpyEditor from the start menu). You may need to wait a minute the first time it starts.
  2. When the program starts up you should see the blinky.mpy file in the mpyEditor window, you will see the name in the tab at the top of the window area. If you do then you can skip the next 3 steps.  (goto step 6) . It should look like window below, if it doesn’t then you will need to reset the mpyEditor back to the startup state, see here for details.
  3. If it is not already plugged in then Plug your Launchpad with MSP430 microcontroller chip into the USB socket of the computer. After a few seconds in the bottom part of the mpyEditor  the Launchpad status should change from Searching or Not Connected to a green COMxx: MSP430Gxxxx ,  note: the xxxx numbers will depend on your Launchpad MSP430 chip and your computer USB port.  (If it still says Searching or Not Connected try re-plugging in the Launchpad board or closing the mpyEditor and restarting  it)
  4. In the bottom window of the mpyEditor Click on the PROG button. You should see this printed
 (mpy2c started)   ... (mpy2c passed)  wrote: C:\MPYmpy_examples\blinky.c   CPU: msp430g2231
 (mspgcc started)  ... (mspgcc passed) wrote: C:\MPY\mpy_examples\blinky.elf
 (mspdebug started)... (mspdebug passed)    1014 bytes written to msp430g2231

If all went well and you did not make a mistake, then the green led at bottom of the Launchpad board will blink once a second. If however, there was a problem and you didn’t get the same output messages, then you will need to find out what went wrong and try again. (Here are some helpful tips on how to fix your problems)

Making some changes

Once you have it working  try changing both the lines with wait(500) to wait(100) and press PROG again. Look at the Launchpad board. What just happened?

Try changing all the lines with P1_6  to P1_0 and press PROG. Look at the Launchpad board.

If all went well it should flash a lot faster and the red LED should flash instead of the green one.

Congratulations, you are now a programmer!

If you had problems and managed to fix them, then you are an even better programmer!

Running the snippets

The following sections contain example program snippets which can be run on your Launchpad board.  Just select the example with your mouse and type Ctrl-C to copy it and then type Ctrl-V to paste it directly into the mpyEditor file tab. Then hit the Prog button to flash it into the Launchpad. To restart the mpy program press the button marked RESET on the Launchpad board. If you have any problems  go to the troubleshooting pages here.