#I have another test code let me show you
1 messages · Page 1 of 1 (latest)
you need to pip install adafruit-board-toolkit
telling the board you want to write from the PC:
python host.py COM* WRITE
and READ to revert
i'll try in a fews minutes
host-auto works like that:
- change the
modify_the_filefunction to edit the file (takes the current content and returns the new content) - set DRIVE in it to the letter that the board appears at
- the FILE_NAME to the name of the file you wish to edit
- set the PORT or give it on the command line, or leave blank to use the first board found
- call
python host-auto.py COMPORT(or no COMPORT)
it: - sends the command to put the board into WRITE mode
- waits for the drive to be available again
- reads the file and modifies it
- sends the command to put the board into READ mode
I have tested it here, but not on windows, there might be quirks
is something supposed to happens ?
cuz nothing is happening lol
oooh
gg !
it work ! (with the manual script)
can I put function here (1) and use them in the lopp ? (2)
or they need to be in the loop
yes you can declare functions and then call them when you need to
perfec
one issue of the previous code is that it would close the serial connection too soon, it now waits until all bytes are sent
How does the auto host work ? i'm not quite sure
there's comments in the file
adafruit_board_toolkit lists serial ports of Circuitpython boards, so it finds the one you give it, remembers the unique serial-number to so it can find it later after the board has reset
if tests the existence of the drive by looking for boot_out.txt, since I'm not sure how windows handles drive letters and paths
so when the board reboots it waits until the drive is back up
ah I have a problem
then finds the file, and reads it with the json module, or creates an empty dictionary if not found or not valid. You might want to adapt that to yours (you might prefer a list instead of a dictionary by default)
since my pico run when pluged, it try to write to the config file
but it's in read only mode
then it crash the python code
and i'm not able to switch
I made READ and WRITE do that "WRITE" means "the PC wants to write", so the board should write "RO" in NVM memory, which will make the drive "readonly" from Circuitpython on reset
Yeah I got that, i'll just put my thing in a try loop, so if it crash, no big deal for the rest of the script
note that if you write down the serial number, it is possible to configure the host to find the board by serial number
(so you don't have to enter the COM port)
or actually it picks the first it finds if you don't give it anything
(I have multiple boards connected, so that wouldn't work for me 😉 )
think i'll add a "remember this device" button
I can also make a version that uses discotool (another pip install) which should be able to find the drive itself too, without having to give the letter
so now it can switch and all
but it cant seem to be able to edit that file
uh
I wanted to fix an error in the code
but it seems i've broken the thing
I cant switch to read from write
or make the thing switch
stuck in read only mode
that suck
is there a hard reset feature or something ?
there is safe mode
i'm stuck in read only mode and I cant change it back
the host script dont do anything
after reset you have ~1s to press reset again and the board boots in safe mode
unless it's corrupted, which might happen sometimes when the board is disconnected or reset while a file is still open, but that shouldn't happen with thonny or my code here which should flush and close the file before resetting the board
in any case, don't forget to backup your code, and if things go terribly wrong you can always erase the board and reinstall Circuitpython
wdym by reset ?
you can add a reset button between the RUN pin and GND
do you have pins and breadboard ?
you can always do it manually by touching the pins with a wire
I dont have a pins, but I have a breadboard and a pico explorer (I ordered pins cuz I thought they were included)
I have wires tho
uh
I touched the pins
it just disconnected and reconnected the pico lol
yeah reset
but I still cant write
do it once, and a second time within 1s
it's a double-click but with a wire
most boards have a neopixel that blinks yellow to tell you when you can press reset to go into safe mode
k i'm in safe mode
this time I'm putting try catch so I aint stuck like this
Idk what got f#cked, maybe my script I guess
I did shove a button into pins to make a reset button, solderless 😉
well that button is on the wrong side but it's the idea
unfortunately captain resetti is not compatible with the W
eh ? somethings wrong, cuz even after a reset and a backup of a working script it goes back into read only and wont run the code
and thonny tell me that the device is busy or not responding
ima yeet the file editing part
pretty sure that's the issue
gotcha
oh i'm so retarted
ah ouaip mais sans le code je peux pas dire 😛
ah mais ptn x)
fallait le dire que t'étais français
en gros j'ai foiré l'ident
le truc qui ouvrait le fichier config.json était dans une classe
au lieu d'être dans la loop
bon, c'est toujours pt ptdrr 😭
ah bein non
OHHH
MAIS
C'EST MON CODE QUI A FONCTIONNER
en gros j'ai fait un "killswitch" pour éviter les problèmes et ça a marché !
trop bien
ah, pas totalement visiblement
des fois ça veut
des fois ça veut pas
ben ça progresse en tout cas c'est déjà ça 😉
ouais !
hmmm
ah oe c'est peut être ça ? j'ai entendu dire que LED c'est plus comme ça
GP4 utilisé c'est probablement une erreur de code, board.LED est GP25
et oui, la LED est connectée au module wifi, donc inutilisable pour le moment dans CP, tandis que GP25 sert à la communication avec le module wifi
et il semblerai que si j'envoie READ par exemple
mais que le truc recois pas
et se reco
là ça se remet
faut pas flush un truc ?
après
j'ai l'impression c'est la loop le problème
ça crash qu'a la fin de la fonction
j'vais tenter un truc
le programme n'a pas l'air de remettre les pin en DOWN et laisse sur UP
fin j'espère juste ça va pas me faire une loop infini mdrr
ah attend, est ce que le pin qui s'occupe de lire/écrire serai pas le GP4 ?
ou thonny ?
eeh attend un peu
c'est le pin 4 ça ?
y a pas de pin c'est logiciel
ah

jvois pas trop cékoi le problème, après avoir complété le script, j'ai l'impression il retourne le faire encore
écrire sur le disque fait redémarrer le code, il faut prendre ça en compte (l'autoreload se désactive) mais le pin en cours c'est quand on init un pin plus d'une fois, c'est probablement une erreur de logique dans le code
qu'on peut partager avec le bouton +
ah, mais j'ai l'impression que ça veut pas écrire tout court
après c'est peut être le fait que je run le script depuis thonny ?
oula, bcp de chose
je sais pas trop comment fonctionne Thonny, mais je crois effectivement qu'il ne fait pas de reload, donc lancer code.py avec le bouton "run" va causer des soucis
mais bon ça tourne tout seul normalement
ouais j'crois c'est ça
j'ai repassé en writing mode, ça a unlink le pico de thonny
et là ça a marché
genre le config.json le Ex est passé de yes à no
ouais
c'était thonny le problème
tout roule maintenant
j'ai peu être parlé trop vite
impossible de repasser en READ / WRITE
le truc ne répond plus
ça plante quelque part
et si je relance l'exec thonny ça va repasser le truc en WRITE / READ
oula
en fait j'ai l'impression c'est hasardeux
y a d'autres applis qui tournent ?
nop
des trucs comme Cura, assez courant chez les maker, peuvent bloquer les ports série un peu au pif
ça plante après avoir lancé le script et désactiver l'éxec du code principal
fin genre
ça lance le code principal 1 fois, ensuite ça le désac via le fichierconfig et a la prochaine loop ça check si oui ou non il peut exec le code principal
je l'ai unplug replug
et j'ai pu le repasser en write
sacré bazar
c'est trop passionnant j'adore
après
c'est pas un big problème que le bordel ne marche plus après l'execution avec le killswitch, vu que de toute façon
c'est sensé duré que qlq secondes
et après hop tu change de pc
c'est juste pour éviter que quand tu reviens sur ton ordi principal, ça exec le script quand même
pour ce soir j'ai fini mdr, en tout cas grand merci pour les scripts fourni
bonne soirée/nuit
merci à toi aussi
Note avant que j'oublie: on pourrait aussi tenter d'ajouter une sécurité en faisant éjecter le drive avant de demander le reboot, pour réduire les risques de corruption, il faudrait chercher comment faire ça en python (c'est coté PC)
Une commande shell ?
malheureusement je crois pas qu'on puisse le faire avec shutil, mais en cherchant un peu, y a des commandes, d'une part pour "éjecter" le drive, et d'autre part pour enlever la lettre une fois que c'est fait (sinon elle risque de rester comme un lecteur de CD vide apparemment)
ce code est spécifiquement pour éjecter tout disque qui est ajouté, mais on peut en extraire la partie utile https://github.com/iamgyz/usbEjector