Syntax error

Hello, I have just got my pi 3 and I’m messing around with the blinkt programming. I’m trying to follow these instructions: Getting Started with Blinkt! - Pimoroni Yarr-niversity
However, it’s giving me a syntax error on the 3rd from last line “set_pixel(x, r, g, b,)”
Any help would be greatly appreciated

What’s the actual error?
Are you running it from python 2 or 3?
Are you running it from Thonny or from command line?

It’s on python 3 and I’ll I’m getting is just “syntax error” with it highlighting the set_pixel in red. I’m not sure what thorny is I’m afraid I just opened up a new file in python 3 and copied the code

If you have installed the PiOS with Desktop, Thonny shows up as a menu option under programing. It’s a Python IDE.
It sounds like you running it from command line?
Posting how your running it from start to finish may help?

Okay I’ve got it to work but only the lights 0,1,2 are working. I’ve made sure all the pins are in. Any tips?

That screen capture shows that your running it in Python 2. Try
python3 /home/pi/....etc

I have a Blinkt, haven’t used it in a while though. Are you running the latest version of PiOS?

I’ve doubled checked and made a new file on python 3 with the same code. Again only the light 0-2 are on. Yes my pi is fully up to date also

Looks from that screenshot that you have an uppercase ‘S’ in “Set_pixel”

Python is case sensitive - try it with set_pixel (lower case S)

1 Like

Can’t see the forest for the trees. Thankyou @hegdav70, I totally missed that. I guess I just assumed he clipped and pasted like I do most times.

1 Like

Done but again only lights 0,1,2 are lighting up

Sounding like a hardware issue to me?

Again, not sure as the screenshot’s a wee bit blurry to me, but looks like the indentation of your code is a bit off. In the example on https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-blinkt, the show() and sleep lines are aligned under the opening for loop:

    for x in range(8):
        offset = x * spacing
        h = ((hue + offset) % 360) / 360.0
        r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)]
        set_pixel(x, r, g, b)
    show()
    time.sleep(0.001)

Whereas you have them all at the same level (or at least it looks like it to me with my dodgy eyesight)

    for x in range(8):
        offset = x * spacing
        h = ((hue + offset) % 360) / 360.0
        r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)]
        set_pixel(x, r, g, b)
        show()
        time.sleep(0.001)

Python (IMO) is idiotic in its use of whitespace as syntax, but that’s the way it is - those indents are important - see if that helps …

D

Yeah, indents are a big deal. Run in an IDE you’ll get weird error messages along the lines of
unexpected indent where indent wasn’t expected
or
no indent where indent was expected

Something like that anyway, lol.