0

delay before starting script
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

delay before starting script

by lmwilco1 on Sun Dec 02, 2018 1:05 pm

I have a Feather M4 with a NeoPixel 24 LED ring. I am using the example code with a couple of modifications. When I save the code it runs and displays the start and end of the init. Then it does nothing for ~25 seconds and then the python code starts again and the second time it is successful.

Any ideas what the feather is doing? I would expect that when I save the python file it would abort the existing script and start running the new file right away. Is this because Windows 10 is not writing the entire file out and it takes 25 seconds to flush the file? If yes then is there a trick to flush the file?

Here is the output of the code:

Code: Select all | TOGGLE FULL SIZE
I save the python file to the feather

ReloadException:
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Start of Init
End of Init

Sits here for 25 or so seconds and then the code reloads again without any user actions

Press any key to enter the REPL. Use CTRL-D to reload.
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Start of Init
End of Init
Before true



Here is the code that I am running:

Code: Select all | TOGGLE FULL SIZE
import time
import board
import neopixel


# On CircuitPlayground Express, and boards with built in status NeoPixel -> board.NEOPIXEL
# Otherwise choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D1
#pixel_pin = board.NEOPIXEL
pixel_pin = board.D10

# On a Raspberry pi, use this instead, not all pins are supported
#pixel_pin = board.D18

# The number of NeoPixels
#num_pixels = 10
num_pixels = 24

# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB
print("Start of Init")
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.2, auto_write=False,
                           pixel_order=ORDER)

print("End of Init")

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.
#    print(pos)
    if pos < 0 or pos > 255:
        r = g = b = 0
    elif pos < 85:
        r = int(pos * 3)
        g = int(255 - pos*3)
        b = 0
    elif pos < 170:
        pos -= 85
        r = int(255 - pos*3)
        g = 0
        b = int(pos*3)
    else:
        pos -= 170
        r = 0
        g = int(pos*3)
        b = int(255 - pos*3)
    return (r, g, b) if ORDER == neopixel.RGB or ORDER == neopixel.GRB else (r, g, b, 0)


def rainbow_cycle(wait):
    for j in range(255):
        for i in range(num_pixels):
            pixel_index = (i * 256 // num_pixels) + j
            pixels[i] = wheel(pixel_index & 255)
        pixels.show()
        time.sleep(wait)

print("Before true")

while True:
    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((255, 0, 0))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((255, 0, 0, 0))
    pixels.show()
    time.sleep(1)

    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((0, 255, 0))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((0, 255, 0, 0))
    pixels.show()
    time.sleep(1)

    # Comment this line out if you have RGBW/GRBW NeoPixels
    pixels.fill((0, 0, 255))
    # Uncomment this line if you have RGBW/GRBW NeoPixels
    # pixels.fill((0, 0, 255, 0))
    pixels.show()
    time.sleep(1)

    rainbow_cycle(0.01)    # rainbow cycle with 1ms delay per step

lmwilco1
 
Posts: 3
Joined: Mon Jul 17, 2017 8:03 pm

Re: delay before starting script

by lmwilco1 on Mon Dec 03, 2018 11:29 pm

The issue was the editor was not forcing the OS to flush the changes to disk. In order to have SlickEdit work do the following:
1) Download a program that will sync the disk from Microsoft https://docs.microsoft.com/en-gb/sysinternals/downloads/sync.
2) Create a Macro by editing the vusrmacs.e and add the following code. If you don't have that file create any simple macro using the Macro - Record menu option. This example is for the D drive, If your feather is another drive change the D on the fifth and seventh line to match your drive letter.
3) Load the macro by going to Macro - Load Module and select your vusrmacs.e file.
4) Anytime you write a file to the D drive SlickEdit will sync the drive and the feather will have the entire new file immediately.

Code: Select all | TOGGLE FULL SIZE
void _cbsave_do_sync()
{
   message("saving file")
   _str drive = strip_filename(p_buf_name, 'N');          \
   if ( pos('D:', drive) != 0 ) {
      message(p_buf_name);    // goes to status line for debug
      shell('sync64.exe  D','QA');
   }                 
}


Thanks to Graeme on the SlickEdit Community site for giving me the script to accomplish this.

lmwilco1
 
Posts: 3
Joined: Mon Jul 17, 2017 8:03 pm

Re: delay before starting script

by danhalbert on Fri Dec 14, 2018 12:11 am

Thanks for this - I added brief info about SlickEdit and a link to this forum post in our section on code editing:
https://learn.adafruit.com/welcome-to-c ... iting-code
(a while ago, and forgot to note that here)

danhalbert
 
Posts: 1716
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.