REPL not working, PY code not working

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

REPL not working, PY code not working

Post by Jkkato »

I am new to Python and Circuit playground, but I do have a background in programing and electronics for a technical institute (some 20 years back).

Anyways, I was trying to get the Playground express to play a wave sound and flash the LED's red when shaken. I was cutting and pasting some code examples from the Adafruit website examples, into a single code.py file. It seems that some libraries are not compatible with each other, as I was getting "Pin # is already in use."

The last thing I remember seeing before my real troubles began is something along the lines of "Input # requires a pull up or pull down..." Keep in mind that this is example code from the website so really, it should be fairly reliable. And what I am trying to do at this point is pretty straight forward.

Now, any python code that I try to run works for able 2 seconds, then nothing. AND REPL doesn't work at all now. Just blank. I am using MU, and the serial terminal. It was working up to this point. As it is now, even the simplest code, LED ON/OFF loop with a time delay only works for ~2 seconds and stops. Since the terminal is not working I do see any errors if there is any. Unfortunately I do not have the code.py that I was running. I can't seem to save the code.py to the hard drive once I save it once to the CIRCUITPY drive with MU. If there is a way, let me know or if there is a backup copy made somewhere... The copy of code.py that was in the drive was deleted when, in my attempt to restore the Circuit Playground, I switch back to MakeCode. I even re flashed the firmware with the instructions on the website.

I can see and write to the CIRCUITPY drive or CPLAYBOOT (if I switch over) and I run the program on the Circuit, but it stops after ~2 seconds. I can't see any REPL or get the Circuit to "Print" to the serial terminal. HELP

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

I want to also point out that when I save a program with Mu (code.py) to the Circuitpy drive, it doesn't start right away like it should (and used to). I have to press the reset button for the code to start...

Update... Still tinkering around with this. I switched back to MakeCode and it SEEMS to be working as normal, but I want to play .wav files and (as far as I have read) can only be done in CircuitPython.

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

I thought this was where I could get help with Adafruit products. Has any support people even looked at my post?

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: REPL not working, PY code not working

Post by adafruit_support_carter »

It sounds like your board may be in a weird state, so it's probably best to try and get it back to a known state. This process will erase any programs you have saved to CIRCUITPY, so copy those off the board first.

Then, double press reset to get into bootloader mode so that you see the CPLAYBOOT folder. Download a copy of the latest firmware:
https://github.com/adafruit/circuitpyth ... -3.0.2.uf2
and drag that UF2 file to the CPLAYBOOT folder. This should update you to the latest CircuitPython.

Next, go to the REPL and do this to clean your file system:
https://learn.adafruit.com/welcome-to-c ... stem-18-15

You should now have a functional board. However, we also erased all the libraries. So download a copy of the bundle:
https://github.com/adafruit/Adafruit_Ci ... ses/latest
and install as described here:
https://learn.adafruit.com/welcome-to-c ... undle-11-4

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

OK. I had already tried all these steps while troubleshooting this issue over the last two weeks (when no one was responding to my first post), but not all at once. So I followed your instructions now.

Although MU still can't serial connect to the CPX, I installed PUTTY, which can. I also uninstalled MU and reinstalled it, but the communication problem remains. As does the "not restarting when downloading code."
In addition to all the problems I described earlier, Now when I run my code I get a new error. When I tap the CPX, it used to flashe the neopixels and play a .wav file. This is what appears in PUTTY.

Code: Select all

Tap detected
Traceback (most recent call last):
  File "main.py", line 66, in <module>
  File "adafruit_circuitplayground/express.py", line 684, in play_file
  File "adafruit_circuitplayground/express.py", line 682, in play_file
MemoryError: memory allocation failed, allocating 512 bytes
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Press any key to enter the REPL. Use CTRL-D to reload.
This code was working before I wiped the CPX and reinstalled the lib. I checked and there is express.mpy file in the /lib/adafruit_circuitplayground/ directory... should this be .py not .mpy?
This is line 66 of Main.py

Code: Select all

            cpx.play_file(audiofiles[0])
audiofiles is defined as... (and both files have been recopied to the Circuitpy drive.

Code: Select all

audiofiles = ["Gobble.wav", "Purring.wav"]

I am attaching my whole code. Note I am still editing it while also troubleshooting the other errors.

Code: Select all

# My Turkey Code.py
# Objective
# 1 to glow (different colours?)
# 2 to flash and make gobble sound when (Tap or Shake) loud noise
# 3 to make purr sound occasionally
# 4 to use the red LED to show the program running while waiting to start
# 5 to time out and goto sleep...?
#
# there is a 5 second start up delay

from adafruit_circuitplayground.express import cpx
import time
import random

# Set variables
Init = True
Start = False
REDLOW = (30, 0, 0)
REDHI = (255, 0, 0)
BLULOW = (0, 0, 30)
BLUHI = (0, 0, 255)
GRNLOW = (0, 30, 0)
GRNHI = (0, 255, 0)
WHTLOW = (30, 30, 30)
WHTHI = (255, 255, 255)
BLK = (0, 0, 0)
audiofiles = ["Gobble.wav", "Purring.wav"]
Flash = True
MinLevel = 1
MaxLevel = 20
Glow = MinLevel
delayF = 2
delayM = .1
ShakeLv = 13
delayCnt = 0
Rand = 1
Multip = 1000   # random number multipier

cpx.pixels.brightness = 0.3
cpx.detect_taps = 1
cpx.red_led = True

while True:
    
    if Init:
        Init = False
        print("Welcome Thanksgiving Guests")
        print("Please wait 5 seconds.")
        time.sleep(5)

    if cpx.tapped:
        print("Start detected")
        Rand = (random.random() * Multip)
        Start = True
        cpx.red_led = False
    
    while Start:
        
        # Gobble
#        if cpx.tapped:
        if cpx.shake(ShakeLv):
            print("Tap detected")
            print("Gobble Gobble 1")
            # FireBall 1
            cpx.pixels.fill(REDHI)
            cpx.play_file(audiofiles[0])
            cpx.pixels.fill(REDLOW)
        
            # FireBall 2
            time.sleep(delayF)
            print("Gobble Gobble 2")
            cpx.pixels.fill(BLUHI)
            cpx.play_file(audiofiles[0])
            cpx.pixels.fill(BLULOW)
            # FireBall 3
            time.sleep(delayF)
            print("Gobble Gobble 3")
            cpx.pixels.fill(GRNHI)
            cpx.play_file(audiofiles[0])
            cpx.pixels.fill(GRNLOW)
            # FireBall 4
            time.sleep(delayF)
            print("Gobble Gobble 4")
            cpx.pixels.fill(WHTHI)
            cpx.play_file(audiofiles[0])
            cpx.pixels.fill(BLK)
            time.sleep(0.5)

        # Purring

        if delayCnt > (Rand):
            print("Purring...")
            delayCnt = 0  # Reset the count and random number
            Rand = (random.random() * Multip)
            cpx.play_file(audiofiles[1])
    #        cpx.red_led = True
        else:
            # Increment the delay counter
            delayCnt += 1
            print(delayCnt, " < ", (Rand))
            time.sleep(delayM)
            if Flash:
                print("glow Up")
                Glow += 1
                if Glow > MaxLevel:
                    Flash = False
            else:
                cpx.red_led = False
                print("glow Dn")
                Glow -= 1
                if Glow < MinLevel:
                    Flash = True
                    Glow = MinLevel
        
            cpx.pixels.fill((int(Glow), 0, 0))
    else:
        print("Waiting to start (Tap)")
        cpx.red_led = not cpx.red_led
        time.sleep(delayM)
Attachments
Gobble.zip
The two wav files.
(367.35 KiB) Downloaded 16 times
Last edited by Jkkato on Fri Oct 05, 2018 11:12 pm, edited 1 time in total.

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

update. I can run this modified demo code and it works.

Code: Select all

from adafruit_circuitplayground.express import cpx
 
cpx.play_file("Gobble.wav")
Still don't know what is going on...

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

OK working backwards from before I did the wipe and reload of the CPX, I was trying to implement one of the rainbow circle demo codes. I had added the following line, which apparently breaks the cpx.play_file library.

Code: Select all

cpx.pixels.brightness = 0.3
code working again.

Also, I do have another CPX (Adabox 008) which I had been reluctant to open, since I didn't want to wreck it (not knowing what my problem was). But I tried the new CPX while troubleshooting the above bug. Now that I fixed the above bug, and switching back to the original CPX, the communications seem to be fixed for both... Fingers crossed.

So I may have figured it out myself. Plugging in another CPX seems to have fixed the communication Mu problems. And removing the pixels.brightness fixed the play_file bug.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: REPL not working, PY code not working

Post by adafruit_support_carter »

I checked and there is express.mpy file in the /lib/adafruit_circuitplayground/ directory... should this be .py not .mpy?
Remove this from the /lib folder. It is built into the CircuitPython firmware for the CPX. If the file is present in /lib, it will try to import it. And since it's a fairly large library, it can't fit when it's already in the firmware.

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

adafruit_support_carter wrote:
I checked and there is express.mpy file in the /lib/adafruit_circuitplayground/ directory... should this be .py not .mpy?
Remove this from the /lib folder. It is built into the CircuitPython firmware for the CPX. If the file is present in /lib, it will try to import it. And since it's a fairly large library, it can't fit when it's already in the firmware.

When I delete this file the CPX doesn't work at all.

Code: Select all

ImportError: no module named 'adafruit_circuitplayground.express'
UPDATE:
OK. I may have figured it out. Instead of just deleting the .mpy file. I renamed the adafruit_circuitplayground directory. I hope this fixed the random memory allocation error I was getting too.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: REPL not working, PY code not working

Post by adafruit_support_carter »

Sorry, I wasn't too clear on what to delete. Yep, you needed to delete the folder in /lib also. With it there, CP was still trying to look for the library there instead of the baked in version.

Does it seem OK now?

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

I am still having problems. Now it is stuck in CIRCUITPY mode. When I double click the reset button, the neopixels light up green but the CPLAYBOOT drive doesn't appear ever. I thought I would start another thread, since it seems separate from my previous problem.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: REPL not working, PY code not working

Post by adafruit_support_carter »

Try again - the timing can be tricky sometimes.

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »

adafruit_support_carter wrote:Try again - the timing can be tricky sometimes.
You know I have been trying for about 10 hours over the last three days...

User avatar
Jkkato
 
Posts: 24
Joined: Tue Mar 28, 2017 7:04 pm

Re: REPL not working, PY code not working

Post by Jkkato »


User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: REPL not working, PY code not working

Post by adafruit_support_carter »

OK. We'll troubleshoot this one over there.

Locked
Please be positive and constructive with your questions and comments.

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”