Description
I have been seeing the same issue discussed in Issue #111
on a linux (Ubuntu 16.04 on a Mac Mini box) system. Since #111 focused on the Windows platform, it was recommended that a new issue be opened for linux.
What I have found is the when editing and saving a file on the circuitPython device, I often get a "syntax error" the first time I try to execute the saved script.
With guidance from @dhalbert here are a few consistent observations:
The problem only occurs if sufficient time is not allowed after saving the file and executing it.
It also depends on the editor used to save the file.
Using "gedit" I found that I had to wait ~30 seconds after saving the file before rebooting and executing it to reliably avoid the syntax error. I tried several delay times and found anything less than 30 seconds to be unreliable.
Using "nano" to edit the file, I was unable to cause the error no mater how quickly I rebooted.
One other note is that the problem did not occur at all with a very short (~300 byte) script. This is consistent with the discussion in #111
These tests were executed with CirCuitPython 2.0.0-beta-1.4 on a Metro_M0_Express - with a Jewel(7 Neopixel) connected to D2
Here is an example of the syntax error and the script.
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 2.0.0-beta.1-4-gf6a7025 on 2017-08-11; Adafruit Metro M0 Express with samd21g18
import jewel_rainbow
Traceback (most recent call last):
File "", line 1, in
File "jewel_rainbow.py", line 45
SyntaxError: invalid syntax
# Gemma IO demo - NeoPixel
from digitalio import *
from board import *
import neopixel
import time
pixpin = D2
numpix = 7
#led = DigitalInOut(D13)
#led.direction = Direction.OUTPUT
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3,auto_write=False)
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if (pos < 0):
return (0, 0, 0)
if (pos > 255):
return (0, 0, 0)
if (pos < 85):
return (int(pos * 3), int(255 - (pos*3)), 0)
elif (pos < 170):
pos -= 85
return (int(255 - pos*3), 0, int(pos*3))
else:
pos -= 170
return (0, int(pos*3), int(255 - pos*3))
def rainbow_cycle(wait):
for j in range(255):
for i in range(len(strip)):
idx = int ((i * 256 / len(strip)) + j)
strip[i] = wheel(idx & 255)
strip.show()
time.sleep(wait)
try:
while True:
rainbow_cycle(0.001)
except:
pass
finally:
for i in range(len(strip)):
strip[i] = (0,0,0)
strip.show()