r/MicroPythonDev • u/[deleted] • Jun 07 '24
r/MicroPythonDev • u/Gloppinboobin • May 26 '23
Online IDE?
Does anyone know of any good online micropython IDEs? I was hoping to run code from it to a Pi Pico. Thanks!
r/MicroPythonDev • u/GBAGuy-007 • Mar 11 '23
Run a Matrix keyboard and code on Pi Pico?
Hi all! I decided to pick up a Raspberry Pi Pico for a side project of mine but I've gotten to the point where I'm not sure what to do next... I'm new to the coding scene (aka I have no idea what I'm doing) but my goal was to use a matrix keyboard of tact switches connected to the Pico's GPIO pins to output to a small OLED screen. It would then run code to emulate the Enigma machine from WW2 using micropython. I've gotten the screen to print the keys when pressed and the backspace to delete them, and I've found some compatible code on the Enigma side, but quite honestly, I have no idea how to make them work with one another. I'm also not sure how the enter key would work since it needs to be able to advance multiple menus. Attached is the code I've referenced and a picture of my current status. If any information should be added please let me know. Any tips or insight on the subject would be greatly appreciated!

Print keys to screen:
from machine import Pin,Timer,I2C
import utime
from ssd1306 import SSD1306_I2C
import framebuf
debug=True
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=200000)
oled = SSD1306_I2C(128, 64, i2c)
keyName = [["Z","X","C","V","B","N","M","BACK","ENTER"],
["A","S","D","F","G","H","J","K","L"],
["Q","W","E","R","T","Y","U","I","O","P"]]
keypadRowPins = [16,17,18]
keypadColPins = [6,7,8,9,10,11,12,13,14,15]
row = []
col = []
keypadState = [];
for i in keypadRowPins:
row.append(Pin(i,Pin.IN,Pin.PULL_UP))
keypadState.append([0,0,0,0,0,0,0,0,0,0])
for i in keypadColPins:
col.append(Pin(i,Pin.OUT))
def calc(lst):
operand = []
operator = []
for i in lst:
if(debug):
print(i)
return operand[0]
def keypadRead():
global row
j_ifPressed = -1
i_ifPressed = -1
for i in range(0,len(col)):
col[i].low()
utime.sleep(0.005) #settling time
for j in range(0,len(row)):
pressed = not row[j].value()
if(pressed and (keypadState[j][i] != pressed)): #state changed to high
keypadState[j][i] = pressed
elif(not pressed and (keypadState[j][i] != pressed)): # state changed to low
keypadState[j][i] = pressed
j_ifPressed = j
i_ifPressed = i
col[i].high()
if(j_ifPressed != -1 and i_ifPressed != -1):
return keyName[j_ifPressed][i_ifPressed]
else:
return -1
def printOled(lst):
oledPos = {
"x" : 0,
"y" : 0
}
oled.fill(0)
string = ''
for i in lst:
string += str(i)
l = 0
while(l<len(string)):
oled.text(string[l:l+16],oledPos["x"], oledPos["y"])
oledPos["y"] =oledPos["y"] + 10
l = l+16
oled.show()
shiftFlag = False
signFlag = False
inputList = ['']
oled.show()
oled.fill(0)
oled.show()
oled.text("Pocket",35,15,1)
oled.text("Enigma",35,30,1)
oled.show()
if __name__ == '__main__':
while True:
key = keypadRead()
if(key != -1):
if(key == 'Z' or key == 'X' or key == 'C' or key == 'V' or key == 'B' or key == 'N' or key == 'M' or key == 'A' or key == 'S' or key == 'D' or key == 'F' or key == 'G' or key == 'H' or key == 'J' or key == 'K' or key == 'L' or key == 'Q' or key == 'W' or key == 'E' or key == 'R' or key == 'T' or key == 'Y' or key == 'U' or key == 'I' or key == 'O' or key == 'P'):
inputList[-1] = inputList[-1] + key
elif(key == 'BACK'):
if(shiftFlag):
inputList = ['']
shiftFlag = False
else:
if(inputList == ["error"]):
inputList = ['']
if(inputList != ['']):
if(inputList[-1] == ''):
inputList.pop()
inputList[-1] = str(inputList[-1])[:-1]
else:
inputList[-1] = str(inputList[-1])[:-1]
elif(key == 'ENTER'):
if(inputList[-1] == ''):
inputList.pop(-1)
elif(inputList[-1] != ')'):
inputList[-1] = float(inputList[-1])
try:
ans = calc(inputList)
inputList = [str(ans)]
except:
ans = ''
inputList = []
inputList.append("ERROR FOR ENTER")
printOled(inputList)
print(inputList)Enigma code by Cory Lutton:
# Copyright 2013 Cory Lutton
# Not my code
import sys
__version__ = "1.0"
class Enigma:
""" An Enigma machine is any of a family of related
electro-mechanical rotor cipher machines used for the encryption
and decryption of secret messages. Enigma was invented by
German engineer Arthur Scherbius at the end of World War I.
The early models were used commercially from the early 1920s,
and adopted by military and government services of several countries
 most notably by Nazi Germany before and during World War II.
Several different Enigma models were produced, but the German
military models are the ones most commonly discussed.
"""
def __init__(self):
self.numcycles = 0
self.rotors = []
# Settings for the machine
self.rotorsettings = [("III", 0),
("II", 0),
("I", 0)]
self.reflectorsetting = "B"
self.plugboardsetting = []
# Create the plugboard
self.plugboard = Plugboard(self.plugboardsetting)
# Create each of the rotors
for i in range(len(self.rotorsettings)):
self.rotors.append(Rotor(self.rotorsettings[i]))
# Create reflector
self.reflector = Reflector(self.reflectorsetting)
def print_setup(self):
""" Prints initial setup information """
print()
print("Rotor sequence: (right to left)")
for r in self.rotors:
print(r.setting, "\t", r.sequence)
print()
print("Reflector sequence:")
print(self.reflector.setting, "\t", self.reflector.sequence, "\n")
print("Plugboard settings:")
print(self.plugboard.mapping, "\n")
def reset(self):
""" Reset to initial state """
self.numcycles = 0
for r in self.rotors:
r.reset()
def encode(self, c):
""" Run a cycle of the enigma with one character """
c = c.upper()
if (not c.isalpha()):
return c
# To avoid merely implementing a simple (and easily breakable)
# substitution cipher, every key press caused one or more rotors
# to step before the electrical connections were made.
self.rotors[0].rotate()
# Double step
if self.rotors[1].base[0] in self.rotors[1].notch:
self.rotors[1].rotate()
# Normal stepping
for i in range(len(self.rotors) - 1):
if(self.rotors[i].turnover):
self.rotors[i].turnover = False
self.rotors[i + 1].rotate()
# Passthrough the plugboard forward
index = self.plugboard.forward(c)
# Move through the rotors forward
for r in self.rotors:
index = r.forward(index)
# Pass through the reflector
index = self.reflector.forward(index)
# Move back through rotors in reverse
for r in reversed(self.rotors):
index = r.reverse(index)
# Passthrough the plugboard reverse
c = self.plugboard.reverse(index)
return c
class Rotor:
""" The rotors (alternatively wheels or drums, Walzen in German)
formed the heart of an Enigma machine. Each rotor was a disc
approximately 10 cm (3.9 in) in diameter made from hard rubber
or bakelite with brass spring-loaded pins on one face arranged
in a circle; on the other side are a corresponding number
of circular electrical contacts. The pins and contacts represent
the alphabet  typically the 26 letters A–Z.
Setting Wiring Notch Window Turnover
Base ABCDEFGHIJKLMNOPQRSTUVWXYZ
I EKMFLGDQVZNTOWYHXUSPAIBRCJ Y Q R
II AJDKSIRUXBLHWTMCQGZNPYFVOE M E F
III BDFHJLCPRTXVZNYEIWGAKMUSQO D V W
IV ESOVPZJAYQUIRHXLNFTGKDCMWB R J K
V VZBRGITYUPSDNHLXAWMJQOFECK H Z A
VI JPGVOUMFYQBENHZRDKASXLICTW H/U Z/M A/N
VII NZJHGRCXMYSWBOUFAIVLPEKQDT H/U Z/M A/N
VIII FKQHTLXOCBJSPDZRAMEWNIUYGV H/U Z/M A/N
"""
def __init__(self, settings):
""" Setup an enigma transformation rotor """
self.setting = settings[0]
self.ringoffset = settings[1]
self.base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
self.settings = {
"I": ["EKMFLGDQVZNTOWYHXUSPAIBRCJ", ["R"], ["Q"]],
"II": ["AJDKSIRUXBLHWTMCQGZNPYFVOE", ["F"], ["E"]],
"III": ["BDFHJLCPRTXVZNYEIWGAKMUSQO", ["W"], ["V"]],
"IV": ["ESOVPZJAYQUIRHXLNFTGKDCMWB", ["K"], ["J"]],
"V": ["VZBRGITYUPSDNHLXAWMJQOFECK", ["A"], ["Z"]],
"VI": ["JPGVOUMFYQBENHZRDKASXLICTW", ["AN"], ["ZM"]],
"VII": ["NZJHGRCXMYSWBOUFAIVLPEKQDT", ["AN"], ["ZM"]],
"VIII": ["FKQHTLXOCBJSPDZRAMEWNIUYGV", ["AN"], ["ZM"]]}
self.turnovers = self.settings[self.setting][1]
self.notch = self.settings[self.setting][2]
self.sequence = None
self.turnover = False
self.reset()
def reset(self):
""" Reset the rotor positions """
self.base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
self.sequence = self.sequence_settings()
self.ring_settings()
def sequence_settings(self):
""" Set the intial sequence """
return self.settings[self.setting][0]
def ring_settings(self):
""" Apply the initial ring settings offset """
for _ in range(self.ringoffset):
self.rotate()
def forward(self, index):
""" Move right to left through the rotor """
return self.base.index(self.sequence[index])
def reverse(self, index):
""" Move left to right back through the rotor """
return self.sequence.index(self.base[index])
def rotate(self):
""" Cycle the rotor 1 position """
self.base = self.base[1:] + self.base[:1]
self.sequence = self.sequence[1:] + self.sequence[:1]
if(self.base[0] in self.turnovers):
self.turnover = True
class Reflector:
""" With the exception of the early Enigma models A and B,
the last rotor came before a reflector (German: Umkehrwalze,
meaning reversal rotor), a patented feature distinctive of the
Enigma family amongst the various rotor machines designed
in the period. The reflector connected outputs of the
last rotor in pairs, redirecting current back through the
rotors by a different route. The reflector ensured that
Enigma is self-reciprocal: conveniently, encryption was
the same as decryption. However, the reflector also gave
Enigma the property that no letter ever encrypted to itself.
This was a severe conceptual flaw and a cryptological mistake
subsequently exploited by codebreakers.
Setting Wiring
Base ABCDEFGHIJKLMNOPQRSTUVWXYZ
A EJMZALYXVBWFCRQUONTSPIKHGD
B YRUHQSLDPXNGOKMIEBFZCWVJAT
C FVPJIAOYEDRZXWGCTKUQSBNMHL
"""
def __init__(self, setting):
self.setting = setting
self.base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
self.settings = {"A": "EJMZALYXVBWFCRQUONTSPIKHGD",
"B": "YRUHQSLDPXNGOKMIEBFZCWVJAT",
"C": "FVPJIAOYEDRZXWGCTKUQSBNMHL"}
self.sequence = self.sequence_settings()
def sequence_settings(self):
""" Set the intial sequence """
return self.settings[self.setting]
def forward(self, index):
""" Passthrough the reflector. """
return self.sequence.index(self.base[index])
class Plugboard:
""" The plugboard (Steckerbrett in German) permitted variable wiring
that could be reconfigured by the operator.
It was introduced on German Army versions in 1930, and was soon adopted
by the Navy as well. The plugboard contributed a great deal to the
strength of the machine's encryption: more than an extra rotor would
have done. Enigma without a plugboard (known as unsteckered Enigma)
can be solved relatively straightforwardly using hand methods;
these techniques are generally defeated by the addition of a plugboard,
and Allied cryptanalysts resorted to special machines to solve it.
"""
def __init__(self, mapping):
""" mapping = [("A", "B"), ("C", "D")] """
self.base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
self.mapping = {}
for m in self.base:
self.mapping[m] = m
for m in mapping:
self.mapping[m[0]] = m[1]
self.mapping[m[1]] = m[0]
def forward(self, c):
""" Return the index of the character """
return self.base.index(self.mapping[c])
def reverse(self, index):
""" Return the character of the index """
return self.mapping[self.base[index]]
def main():
""" Create and run an Enigma machine. """
machine = Enigma()
ciphertext = ""
try:
plaintext = sys.argv[1]
machine.print_setup()
print("Plaintext", "\t", plaintext)
for character in plaintext:
ciphertext += machine.encode(character)
print("Ciphertext", "\t", ciphertext)
# Reset and Decode same message
machine.reset()
plaintext = ""
for character in ciphertext:
plaintext += machine.encode(character)
print("Plaintext", "\t", plaintext, "\n")
except IndexError:
for plaintext in sys.stdin:
for character in plaintext:
sys.stdout.write(machine.encode(character))
if __name__ == '__main__':
#import cProfile
#cProfile.run('main()')
main()r/MicroPythonDev • u/TheRealMatt6079 • Jan 07 '23
Issue with Micropython inline assembler on Pico - vmov is unsupported
self.raspberrypipicor/MicroPythonDev • u/vshymanskyy • Jun 30 '24
ViperIDE - An Innovative MicroPython IDE for Web and Mobile
viper-ide.orgr/MicroPythonDev • u/squeakyhedge • Sep 29 '23
ili9488 and micropython
I have a 3.5 inch ili9488 SPI display, and I'm trying to get it working with micropython and esp32. I tried using this ili9341 driver but none of the methods did anything. I can't find a micropython driver specifically for the ili9488. if you have this display and you got it working, please tell me the driver you used. thanks.
r/MicroPythonDev • u/agramakov • Sep 21 '24
I Made a Robotic Head Based on Pico and a Tutorial How to Build Your Own!
r/MicroPythonDev • u/wo8e • Aug 11 '24
Wifi not connecting if I'm not connected to the terminal?
Just like it says on the tin, as my first micropython program I wrote an mqtt controlled relay. It worked fine until I disconnected and tried to run it in a proper case. After some blinkenlight debugging, it seems to be getting hung up in the while not sta_if.isconnected(): loop.
As soon as I hook up serial and hit reset, it connects to the wifi like normal.
Any insight would be helpful, TIA.
EDIT: version is micropython_ESP32_GENERIC-20240602-v1.23.0.bin
r/MicroPythonDev • u/WZab • Aug 01 '24
PIO-based touch capacitance sensor with three inputs
reddit.comr/MicroPythonDev • u/JimmyNoStar • Aug 16 '22
why isn't port forwarding my socket server working remotely
Is there a specific port I'm supposed to use for socket servers running on python or micropyhton?
I have tried using port 5000, 8000, 80, 9000 and a few others, yet I still can't access my server outside of my network. I looked up the port to make sure they weren't reserved by INAN or anything I use on my home network and most places I've checked say to use some of the ports I've listed.
I also tried running thmy code on my computer and port forwarding from there and still no connection
I've also tried using different lan and public port at the same time and still not winning.
I'm using an esp32 and I have given it a static ip
Pls help..
r/MicroPythonDev • u/Key-Advisor5912 • Jul 15 '22
Is there a way to use MicroPython on Pi Pico for keyboard inputs?
Hey!
I'm looking around for how to use a pico as a macro keyboard, but every tutorial seems to point to circuit python, which I'm not really in the mood to learn.
Is circuitpython a necessity? or is there a way to do it on micropython?
Thanks!
r/MicroPythonDev • u/oksbwn • Sep 17 '23
Programming #Pi Pico W using #Arduino LAB micro-python #IDE
r/MicroPythonDev • u/Cobbler_Past • Apr 25 '23
Pi Pico Problems with LCD Displays
hey i need some help. im trying to use my pi pico for an lcd display but it keeps giving me an error. im following this tutorial: https://www.youtube.com/watch?v=B8Kr_3xHjqE . my model is GJD 1602IIC. i have triple checked that i have everything hooked up right. this is the error im getting:
Running test_main Traceback (most recent call last): File "<stdin>", line 62, in <module>
File "<stdin>", line 16, in test_main
File "pico_i2c_lcd.py", line 22, in init
OSError: [Errno 5] EIO
if anyone could help itd be greatly appreciated (im happy to provide anything needed to help)
r/MicroPythonDev • u/WZab • Aug 24 '24
How to use the asymmetric ciphers from SSL module to encrypt data?
I'm creating a MicroPython-based device that is supposed to log data in an encrypted form. The idea is that even if the device gets lost, the data can't be read by the unauthorized person. So the data before storing on the SD card will be encrypted with randomly generated AES key. The key itself will be encrypted with the public key of the intended recipient, and stored on the SD card.
The cryptolib module provides the AES implementation. However the asymmetric ciphers are available only in the SSL module.
>>> import ssl
>>> s1=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
>>> s1.get_ciphers()
['TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384', 'TLS-ECDHE-ECDSA-WITH-AES-256-CCM', 'TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384', 'TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA', 'TLS-ECDHE-ECDSA-WITH-ARIA-256-GCM-SHA384', 'TLS-ECDHE-ECDSA-WITH-ARIA-256-CBC-SHA384', 'TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256', 'TLS-ECDHE-ECDSA-WITH-AES-128-CCM', 'TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256', 'TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA', 'TLS-ECDHE-ECDSA-WITH-ARIA-128-GCM-SHA256', 'TLS-ECDHE-ECDSA-WITH-ARIA-128-CBC-SHA256', 'TLS-RSA-WITH-AES-256-GCM-SHA384', 'TLS-RSA-WITH-AES-256-CBC-SHA256', 'TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384', 'TLS-ECDH-RSA-WITH-AES-256-CBC-SHA', 'TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384', 'TLS-RSA-WITH-AES-256-CCM-8', 'TLS-ECDH-RSA-WITH-ARIA-256-GCM-SHA384', 'TLS-ECDH-ECDSA-WITH-ARIA-256-CBC-SHA384', 'TLS-RSA-WITH-ARIA-256-CBC-SHA384', 'TLS-RSA-WITH-AES-128-CCM', 'TLS-RSA-WITH-AES-128-CBC-SHA', 'TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256', 'TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256', 'TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA', 'TLS-ECDH-ECDSA-WITH-ARIA-128-GCM-SHA256', 'TLS-RSA-WITH-ARIA-128-GCM-SHA256', 'TLS-ECDH-RSA-WITH-ARIA-128-CBC-SHA256']
>>> Is it possible to use those ciphers outside the ssl module, to encrypt the AES key with (e.g.) the RSA public key?
r/MicroPythonDev • u/QuietRing5299 • Jun 30 '24
Need Help Accessing Form Data on the Pico W in MicroPython
import network
import socket
import json
import ure # urequests module is not needed, ure (micro re) is used for regex
def web_page():
html = """<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pico W</title></head>
<body>
<h1>Wi-Fi Configuration</h1>
<form action="/save" method="post">
<label for="ssid">SSID:</label><br>
<input type="text" id="ssid" name="ssid"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Save">
</form>
</body>
</html>"""
return html
def parse_post_data(data):
post_data = {}
pairs = data.split('&')
for pair in pairs:
if '=' in pair:
key, value = pair.split('=')
post_data[key] = value
return post_data
def save_credentials(request):
try:
# Extract the body of the POST request
request_body = request.split('\r\n\r\n')[1]
creds = parse_post_data(request_body)
# Debugging: Print parsed credentials
print('Parsed Credentials:', creds)
# Save to JSON file
with open('wifi_creds.json', 'w') as f:
json.dump(creds, f)
response = 'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n'
response += '<html><body><h1>Credentials Saved</h1></body></html>'
return response
except Exception as e:
print('Error saving credentials:', e)
response = 'HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/html\r\n\r\n'
response += '<html><body><h1>Error Saving Credentials</h1></body></html>'
return response
def ap_mode(ssid, password):
# Setup AP mode
ap = network.WLAN(network.AP_IF)
ap.config(essid=ssid, password=password)
ap.active(True)
while not ap.active():
pass
print('AP Mode Is Active, You can Now Connect')
print('IP Address To Connect to: ' + ap.ifconfig()[0])
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 80))
s.listen(5)
while True:
try:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024).decode('utf-8')
print('Request: {}'.format(request))
if 'POST /save' in request:
response = save_credentials(request)
else:
response = 'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n'
response += web_page()
conn.sendall(response.encode('utf-8'))
conn.close()
except Exception as e:
print('Error:', e)
conn.close()
# Run the AP mode
ap_mode('NAME', 'PASSWORD')r/MicroPythonDev • u/Medical-Ocelot • Feb 06 '24
Which IDE do you use?
I've been using PyCharm - but the REPL has been broken for some time which means you need separate app to do test and debug on. Jetbrains have also just admitted that they aren’t maintaining the Micropython plugin, so even the remaining features might break in future versions. https://youtrack.jetbrains.com/issue/PY-70307
Does anyone have any better recommendations? I use Thonny for its very nice REPL implementation, but it barely counts as an IDE (no understanding of code structure).
r/MicroPythonDev • u/coolxm • Apr 08 '24
mp3 over PWM on an rp2040 in micropython
I saw some old threads that said it wasnt really possible but I would like to play mp3 files over PWM on an RP2040 using micropython.
I was able to run it using circuitpython using audiopwm, but I want to use the _thread package in micropython. I thought most of my conversion problems would be solved using Blinka, but don't see audioPWM in there
Would I need to write my own mp3 decoder library (I saw some have been written for normal Python, I could probably work from that but I have never written C package for python, which those packages are so I would prefer not to have to do that.
I also saw that wav files are possible over PWM so that's nice.
I want to use MP3 to save as much space as possible because I am saving data during runtime too and don't want to fill all my entire 8mb memory.
Any way to make it still work simply?
Thank you
r/MicroPythonDev • u/Wake-Of-Chaos • Jun 03 '24
SHTC3 sensor
Trying to work with a SHTC3 temperature/humidity sensor. I have the I2C address and the device datasheet but can't figure out how to read the two addresses. I'm new to Micropython on a raspberry pi pico. Any help would be appreciated.
r/MicroPythonDev • u/nakedMoleRat420 • Dec 21 '23
Time... How?
Hi all, this may be a dumb question but the internet hasn't come up with a good solution and I am new to Micropython but have a fairly large software background. I am creating a little tide clock using an ESP32 and a servo. I need to work out the best way to get the current time (already have an NTP) and the high/low tide time (have an API for this too. From what I can see Time uses a tuple to represent the time. But I can't see a good way of subtracting this to find the remaining time to a tide. Any help on the best way to use time in Micro Python would be great. I am finding I am way too reliant on full Python libraries!
r/MicroPythonDev • u/Mowo5 • Mar 05 '24
Looking for MicroPython libraries for the IMU on RP2040 connect (LSM6DSOXTR)
Is there a MicroPython library to use the IMU on the Arduino RP2040 connect? It uses the LSM6DSOXTR.
This would be really cool.
r/MicroPythonDev • u/TheRealMatt6079 • Feb 02 '23
Hmac and base64 on micropython rp2040 ?
I was trying to convert this code to work on a Raspberry Pi Pico with Micropython 1.19
api_key = "api_key"
api_secret = "api_secret"
api_passphrase = "api_passphrase"
url = 'https://openapi-sandbox.kucoin.com/api/v1/accounts'
now = int(time.time() * 1000)
str_to_sign = str(now) + 'GET' + '/api/v1/accounts'
signature = base64.b64encode(
hmac.new(api_secret.encode('utf-8'), str_to_sign.encode('utf-8'), hashlib.sha256).digest())
passphrase = base64.b64encode(hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest())
headers = {
"KC-API-SIGN": signature,
"KC-API-TIMESTAMP": str(now),
"KC-API-KEY": api_key,
"KC-API-PASSPHRASE": passphrase,
"KC-API-KEY-VERSION": "2"
}
response = requests.request('get', url, headers=headers)
print(response.status_code)
print(response.json())Hmac and base64 don't appear to be available to me, any way round it?
ps. It's the KuCoin API I'm trying to connect to, if there's an existing micropython library that'd be great but I couldn't find one.
r/MicroPythonDev • u/Peter_sanji99 • Sep 14 '23
Micropython Thonny IDE ESP32
I looking for any material related to sensor data input to the esp32 programme as an array to process to relavent outcome get from terminal.I found some relavent codings from arduino but I need to write from micropython,can anyone giveme the idea?
r/MicroPythonDev • u/cubbieco • Jan 19 '24
Hostname (mDNS) not working Micropython Pi Pico W
Has anybody successfully enabled and used a hostname to connect remotely on a Pi Pico W in Micropython? It works fine for me in CircuitPython but I don't want to use that. Here is my boot.py.
import network
import socket
from time import sleep
import machine
from config import *
def connect():
wlan = network.WLAN(network.STA_IF)
wlan.config(hostname=host)
network.hostname(host)
wlan.active(True)
wlan.connect(ssid, wifipass)
while wlan.isconnected() == False:
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
print(f"Hostname: {network.hostname()}")
try:
connect()
except KeyboardInterrupt:
machine.reset()
import webrepl
webrepl.start()And here is the REPL output:
MPY: soft reboot
Connected on 192.168.86.35
Hostname: meetinginator
WebREPL server started on http://192.168.86.35:8266/
Started webrepl in normal modeI can connect to the WebREPL just fine at 192.168.86.35 but I can't use the hostname like I should. Am I doing something wrong or is the functionality just not there? Remembering the ip address for a bunch of pico Ws around the house just isn't feasable.
r/MicroPythonDev • u/[deleted] • Dec 07 '23
Input issue
Hi I am having issues with input in micropython esp32 that i cant really type anything in
code:
import network
from machine import Pin, SoftI2C
import ssd1306
import time
import socket
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)
sta_if.active(True)
sta_if.connect("-", "-")
for i in range(200):
if sta_if.isconnected():
break
time.sleep(0.1)
if not sta_if.isconnected():
raise ValueError
host = "-"
port = -
time.sleep(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
data = s.recv(1024).decode("utf-8")
print("Received: ", data)
s.sendall(data.encode("utf-8"))
inp = input("whatever ")
print(inp)
r/MicroPythonDev • u/oksbwn • Apr 09 '23