Newbie general question - should Feather devices work when not connected to computer?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
anant479
 
Posts: 5
Joined: Tue Nov 16, 2021 6:10 pm

Newbie general question - should Feather devices work when not connected to computer?

Post by anant479 »

Hi - newbie getting into projects. Awesome site and on my 3rd kit (but still consider myself a newbie)
Question on a neopixel project, but its more of a general question

I am using a Feather ESP32-S2 to drive 30 neopixel strip. The ESP32 is connected to my computer so that I can use Mu to program it. I also have the power side of the neopixels connected to a USB outlet to power them. I also have a 3,7v battery connected to the Batt terminal on the feather.

This set up works great. but the minute I unplug my computer the neopixels start acting weird, they still emit lights, but they don't follow the rainbow cycle etc that I programmed.

So my general question - shouldnt the feathers function as a standalone computer once I program them and they have the py files stored on them? Or do they need to stay connected to the computer? What am I doing wrong?

If it helps here is my code

Code: Select all

"""CircuitPython Essentials NeoPixel example"""
import time
import board

# For internet
import ipaddress
import ssl
import wifi
import socketpool
import adafruit_requests

# For Adafruit IO
import busio
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager


from rainbowio import colorwheel
import neopixel
J
# Definitions For the neopixel
pixel_pin = board.A1
num_pixels = 30
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=1, auto_write=False)

def color_chase(color, wait):
    for i in range(num_pixels):
        pixels[i] = color
        time.sleep(wait)
        pixels.show()
        time.sleep(0.5)


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

RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
PINK = (227, 28, 121)
ORANGE = (255, 83, 73)
WHITE = (255, 255, 255)

TUNGSTEN = (255, 214, 179)  # 2600 KELVIN
HALOGEN = (255, 241, 224)  # 3200 KELVIN
CARBONARC = (255, 250, 244)  # 5200 KELVIN
HIGHNOONSUN = (255, 255, 251)  # 5400 KELVIN
DIRECTSUN = (255, 255, 255)  # 6000 KELVIN
OVERCASTSKY = (201, 226, 255)  # 7000 KELVIN
CLEARBLUE = (64, 156, 255)  # 20000 KELVIN

# STUFF FOR WIFI CONNECT

# URLs to fetch from
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_QUOTES_URL = "https://www.adafruit.com/api/quotes.php"
JSON_STARS_URL = "https://api.github.com/repos/adafruit/circuitpython"

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

print("ESP32-S2 WebClient Test")

print("My MAC addr:", [hex(i) for i in wifi.radio.mac_address])

print("Available WiFi networks:")
for network in wifi.radio.start_scanning_networks():
    print("\t%s\t\tRSSI: %d\tChannel: %d" % (str(network.ssid, "utf-8"), network.rssi, network.channel))
    wifi.radio.stop_scanning_networks()

print("Connecting to %s"%secrets["ssid"])
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("Connected to %s!"%secrets["ssid"])
print("My IP address is", wifi.radio.ipv4_address)

ipv4 = ipaddress.ip_address("8.8.4.4")
print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

print("Fetching text from", TEXT_URL)
response = requests.get(TEXT_URL)
print("-" * 40)
print(response.text)
print("-" * 40)

print("Fetching json from", JSON_QUOTES_URL)
response = requests.get(JSON_QUOTES_URL)
print("-" * 40)
print(response.json())
print("-" * 40)

print()

print("Fetching and parsing json from", JSON_STARS_URL)
response = requests.get(JSON_STARS_URL)
print("-" * 40)
print("CircuitPython GitHub Stars", response.json()["stargazers_count"])
print("-" * 40)

print("done")

pixels.fill((0, 0, 0))
pixels.show()

#  START CODE FOR GET WEATHER
# Use cityname, country code where countrycode is ISO3166 format.
# E.g. "New York, US" or "London, GB"
LOCATION = secrets['timezone']

# Set up where we'll be fetching data from
DATA_SOURCE = "http://api.openweathermap.org/data/2.5/weather?q="+secrets['timezone']
DATA_SOURCE += "&appid="+secrets['openweather_token']

print("Response is", response)


# START THE MAIN LOOP
while True:
    # pixels.fill(HALOGEN)
    #   pixels.show()
    #   Increase or decrease to change the speed of the solid color change.
    #   time.sleep(0.5)

    color_chase(RED, 0.1)  # Increase the number to slow down the color chase
    color_chase(YELLOW, 0.1)
    color_chase(GREEN, 0.1)
    color_chase(CYAN, 0.1)
    color_chase(BLUE, 0.1)
    color_chase(PURPLE, 0.1)

    # rainbow_cycle(0.5)  # Increase the number to slow down the rainbow
Last edited by dastels on Thu Oct 06, 2022 8:07 pm, edited 1 time in total.

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Newbie general question - should Feather devices work when not connected to computer?

Post by dastels »

It will work fine without being connected to a computer. Do you have the grounds of the NeoPixel strip and the Feather connected?

Dave

User avatar
westfw
 
Posts: 2010
Joined: Fri Apr 27, 2007 1:01 pm

Re: Newbie general question - should Feather devices work when not connected to computer?

Post by westfw »

Arduino sketches can hang trying to initialize the USB/Serial connection, when not plugged into something that talks USB.
I don't know whether that's true of circuitPython as well, but you could try commenting out all of your "print" statements (or some equivalent.)

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Newbie general question - should Feather devices work when not connected to computer?

Post by dastels »

That is common in C++, but I haven't experienced in in CircuitPython.

Dave

User avatar
anant479
 
Posts: 5
Joined: Tue Nov 16, 2021 6:10 pm

Re: Newbie general question - should Feather devices work when not connected to computer?

Post by anant479 »

dastels wrote: Thu Oct 06, 2022 8:09 pm It will work fine without being connected to a computer. Do you have the grounds of the NeoPixel strip and the Feather connected?

Dave
Nope, no grounds. Probably a stupid newbie question.. but what do I ground it to? I tried googlling but no luck... I got links to how to ground meat :-) So I'm assuming I connect all the grounds together ... and then connect them to what?

Thanks for the help

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Newbie general question - should Feather devices work when not connected to computer?

Post by dastels »

Together is what you want. All the grounds in the circuit (all the connected bits). Not necessarily power (It sounds like your strip has it's own), but all the grounds. All signals are relative to ground. E.g. what does 5v mean? It means 5 volts more positive than ground. So for 5v to mean the same thing in two connected circuits, their grounds have to be connected. It's like communicating with other people: you need a shared language in order for your (and their) words to make sense to each other.

Dave

User avatar
anant479
 
Posts: 5
Joined: Tue Nov 16, 2021 6:10 pm

Re: Newbie general question - should Feather devices work when not connected to computer?

Post by anant479 »

CircuitPicture.jpg
CircuitPicture.jpg (462.38 KiB) Viewed 66 times
dastels wrote: Sat Oct 08, 2022 6:38 pm Together is what you want. All the grounds in the circuit (all the connected bits). Not necessarily power (It sounds like your strip has it's own), but all the grounds. All signals are relative to ground. E.g. what does 5v mean? It means 5 volts more positive than ground. So for 5v to mean the same thing in two connected circuits, their grounds have to be connected. It's like communicating with other people: you need a shared language in order for your (and their) words to make sense to each other.

Dave
Hi Dave - thanks for the answers. I am only able to mess around with this on the weekends, but appreciate the responses. I attached the ground to the circled ground terminal. Still doesn't behave "correctly" when I disconnect the USB to the computer and attach the battery. I have the ground on the feather connected to the ground from the neopixel strip. Not anything else

The lights seem to light randomly instead of following whats been coded when I disconnect the USB to the computer.

Thanks again for the help, I am going to give up after this and probably start from scratch and do some fundamental learning - was thinking of this course since I'm not great at muddling around on my own :-)

https://www.coursera.org/specialization ... rce=impact

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Newbie general question - should Feather devices work when not connected to computer?

Post by dastels »

First, you need to solder the header pins to the Feather.

Ok, to confirm: you are powering the strip with a separate 5v power supply? If you need a level shifter to convert the Feather's 3.3v signal to a 5v signal the NeoPixels will understand (this is because they are powered by 5v). See https://learn.adafruit.com/adafruit-neo ... ogic-level.

Why the difference between USB and battery (the Feather's logic output level is 3.3v in both cases)? Maybe because the feather ground isn't solidly connected.

Dave

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

Return to “General Project help”