how to put variable in file inside Flash: pycom
-
from machine import ADC import time adc = ADC() fichier=open('valeurenmv.py',"a") while True : bat_voltage = adc.channel(attn=ADC.ATTN_11DB, pin='P16') vbat = bat_voltage.value() # note that the expansionboard 3 has a voltage divider of 1M / 1M to account for # 1M / 1M, ratio = 1:2 vbat = vbat*2 time.sleep(3) print('battery voltage:', vbat, 'mV') fichier.write('\nvbat')Hi , can you help me to put result of variable vbat in file
-
@HAMMOUTI There are several way in Python to create a formatted string with variable. The most common ones are the % operator on strings or the .format method of strings. Both are implemented in MicroPython and well documented in every Python textbook. Just a few simple examples for your case:
fichier.write('\nvbat=%f' % vbat)
or, if you just want the number:
fichier.write('\n%f' % vbat)
or using the format method:
fichier.write('\nvbat={}'.format(vbat))
or
fichier.write('\n{}'.format(vbat)) -

think you for your help, i try this code, but i have this error see capture .
how to fix this error. -
@HAMMOUTI What is the problem. I can't spot it in the capture. The only odd I see is the reported battery voltage.
-
This post is deleted! -
@HAMMOUTI try to change the name of your file "valeurenmv.py" by "valeurenmv.txt" !
Jiemde
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login