• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

cant figure out the error SyntaxError: 'break'/'continue' outside loop and Upycraft

Q&A Forum › Category: ESP32 › cant figure out the error SyntaxError: 'break'/'continue' outside loop and Upycraft
0 Vote Up Vote Down
Damian Hartley asked 5 years ago

Hi Sara
 
I have spent some time trying to self figure out the following ( some is earlier code you helped me with). I only ask when I get really stuck and spent much time googling before I ask RNT
from machine import Pin, I2C, PWM, ADC
from time import sleep
import ssd1306
# fitted a Button used to force machine stop while in code development
# Break workround required to enable uPycraft to get a connection to
# COM Port so can modify code, not needed when final code developed
button = Pin(36, Pin.IN, Pin.PULL_UP)
#PWM frequency
frequency = 50
#Graphics ESP32 Pin assignment
i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
# ESP8266 – Pin assignment
#i2c = I2C(-1, scl=Pin(5), sda=Pin(4))
oled_width = 128
oled_height = 64
display = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
#Thruster Motor assignments
motor = PWM(Pin(5), frequency)
pot = ADC(Pin(34))
pot.width(ADC.WIDTH_10BIT)
pot.atten(ADC.ATTN_11DB)
#simulated battery pot instanceiated object ( not in use at present since trying to read the existing pot first used for pwm as proof of code concept)
bat_pot = ADC(Pin(35))
bat_pot.width(ADC.WIDTH_10BIT)
bat_pot.atten(ADC.ATTN_11DB)
RNT code provided earlier
def scale_value_args(pot_val, in_min, in_max, out_min, out_max):
scale_value = (pot_val – in_min) * (out_max – out_min) / (in_max – in_min) + out_min
return scale_value

#Main body of code after defining above environment ( from earlier RNT assistance )
while True:
pot_val = pot.read()
duty_cycle = scale_value_args(pot_val, 0, 1023, (1023/20), (1023/10))
print(duty_cycle)
motor.duty(int(duty_cycle))
sleep(0.2)
#if (int(duty_cycle)) > 75:# if i comment this out works for pot and hw BUTTON reset i hooked up to force HW reset as I am describing the error to RNT
# Draw a filled rectangle display.fill_rect(x, y, w, h, c) #works ok
display.fill_rect(0, 0, 127, 67, 1)# main white box fill works ok
display.fill_rect(5, 5, 118, 54, 0)# main black box fill works ok
display.fill_rect(12, 10, 12, 44, 1)# first segment works ok
display.fill_rect(30, 10, 12, 44, 1)# second segment works ok
display.fill_rect(48, 10, 12, 44, 1)# third segment works ok
display.fill_rect(66, 10, 12, 44, 1)# fourth segment works ok
display.fill_rect(84, 10, 12, 44, 1)# fifth segment works ok
display.fill_rect(102, 10, 12, 44, 1)# sixth segment works ok
display.show()                 # works ok
# Force exit
if button.value()==True:# I NEED THIS IN TO ALLOW RESETTING OF BOARD TO ALLOW UPYCRAFT TO COM3 Port  CONNECT OTHERWISE CANT CONNECT !!!!!!
break
I need the force exit code in above to allow UpyCraft to get a look in since the board wont allow COM3 connection when code running , if I comment it out i cant reprogram without reflashing firmware which is a real pain to learning. so this allows me to stop the code at the hardware level to give Upycraft a chance to reconnect at the sw level
However I get the following error
Ready to download this file,please wait!
………………
download ok
exec(open(‘micropython_six_segs-the-one.py’).read(),globals())
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<string>”, line 7, in <module>
SyntaxError: ‘break’/’continue’ outside loop
If I comment out the line above as shown in above code and as shown below for reference in explaining with # it works but I need the if statement in the code so I  start comparing values off the pot so I can set segments to extinguish in the display
#if (int(duty_cycle)) > 75:# if i comment this out works for pot and hw BUTTON reset i hooked up to force HW
 
What am i doing wrong, help is appreciated thanks RNT Team

Question Tags: Upycraft and forced break upsets code development
1 Answers
0 Vote Up Vote Down
Damian Hartley answered 5 years ago

Hi Sara
 
Sorted this problem out moved my code to Thonny. I liked upyCraft but the comms issue leaving you in an undeterminate state  added an extra and confusing layer for the understanding of a newbie to micropython. pity since I liked the IDE of UpyCraft

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.