Wipy 2.0 and save data on my pc, not in flash memory
-
@robert-hh to restart the program I mantain the program open and I reuse the command run.
I put gc.collect() in the code, you can see where in the code that I copy to you before, but the error stay. -
@vflorio94 Can you try to start and run the program from a simple terminal emulator like putty or screen. Using the intgrated environments of Atom or VSC may hide or create problems.
-
@robert-hh Is IDLE Python GUI good?
now I need to implement code with more lines, to compare the other data that calcolo_position(1) return in the same function 'acquisizione_interval_pitch()'.
I'm afraid about this, because I think that the error can be show before the end of the acquisition.And more I have to use an interval of acquisition more longer than 20 second, like 120 second.
-
@vflorio94 You can use any editor you like for writing the code on you PC. The PyCom plugin for upload and run is what may create unexpected result. To sort that out, upload your code with ftp (Filezilla) and use a simple serial terminal to run the code.
-
@robert-hh yes, I'll try to use GUI Idle python , but I have some problem with socket
-
@robert-hh I have some difficult to use a serial terminal to run the code, because I have 'import machine' in main, so I have to use socket, but I don't understand how.
Can you hel me?#Sending import socket DEST_IP = "192.168.4.255" UDP_PORT = 15005 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) def sending(msg): sock.sendto(msg, (DEST_IP, UDP_PORT))#main import machine import pycom import time import lib_imu import gc import interval_position import sending #rilevazione posizione centrale corretta print("INIZIO ACQUISIONE") print("Rilevazione posizione corretta") time.sleep(1) position_ok = [] position_ok = interval_position.calcolo_position(6, 1) mean_pos_ok = position_ok[0] print("media posizione corretta", mean_pos_ok[2]) dev_std_ok = position_ok[1] gc.collect() print("FINE Rilevazione posizione corretta") time.sleep(2) print("Rilevazione posizione errata") time.sleep(1) position_no =[] position_no = interval_position.calcolo_position(6, 2) mean_pos_no = position_no[0] dev_std_no = position_no[1] gc.collect() print("FINE Rilevazione posizione errata") time.sleep(1) print("Inizio test pitch") time.sleep(1) # the function below return 1 if the test is completed correctly p = interval_position.acquisizione_interval_pitch(20, 1, mean_pos_ok, mean_pos_no, dev_std_no, 3) del position_ok del position_no if p == 1: stringa = "Acquisizione terminata" sending.sending(stringa) -
@vflorio94 Using a serial terminal is not at all in conflict with "import machine". What you might see is, that once you runa program on your device, the REPL prompt is not available any more.
-
@robert-hh yes , when I run rhe code in Visual Studio code with this main I have this output :
Calcolo media Acquisizione terminata fine prova ╝╝>the program end correctly. And the REPL prompt is not avaiable any more.
Now i don't have anymore the message of error with memory allocation.
but now I try to complete the code with more lines and more implementation -
@robert-hh And I 'm not able to use serial terminal
-
@robert-hh Sorry, but I need your help one more if is possible.
I have to acquire data from IMU for a long time ( 20 minuts) and write the data on file.
but also this time I have the error╝Traceback (most recent call last): File "<stdin>", line 22, in <module> MemoryError: memory allocation failed, allocating 2048 bytes ╝>Here there are the simple code lines that I wrote. This error is terrible for me, probably I make an error on how to do this . please , can you Help me please?
import machine import pycom from machine import Timer import time import lib_imu from machine import I2C from machine import PWM chrono = Timer.Chrono() lib_imu.set_configmode() time.sleep(0.07) lib_imu.set_units() time.sleep(0.3) lib_imu.set_mode('ndof') List =[] chrono.start() while 1 : lap = chrono.read() if lap <= 1200: eul = lib_imu.get_euler() List.append(eul[0]) time.sleep(0.02) else: print("Salvataggio su file") file_dati = open("dati360.txt", "w") file_dati.write(repr(List[1:len(List)])) file_dati.close() print("fine") chrono.stop() del List break -
@vflorio94 So you want first to collect for 1200 seconds data, with a delay of 20 ms each. I do not know how long taking a value needs, if have someting in mind like ~100 ms, which give a list of 10000 entries, and then you want to store that. AFAIK, the basic mp object type needs 8 bytes/entry, so you need 80kbytes for the fill table. Being already low on memory, the list append fails soon, when the runtime engine of micropython wants to allocate more memory for the list, roughly after 128 cycles.
So no, you simply cannot do that with a WiPY2. You have to write to SD in shorter cycles, even if that would interrupt your data acquisition.
Alternatively, use a device with more memory, like a WiPy3. -
@robert-hh So, if i want to collect as more possible data in 1200 s how frequently can i take values?
-
@vflorio94 You should collect & write at the same time. Since the writikng is buffered, most of the write operations will not take long.
-
@vflorio94 The code could look like:
import machine import pycom from machine import Timer import time import lib_imu from machine import I2C from machine import PWM chrono = Timer.Chrono() lib_imu.set_configmode() time.sleep(0.07) lib_imu.set_units() time.sleep(0.3) lib_imu.set_mode('ndof') with open("dati360.txt", "w") as file_dati: chrono.start() lap = chrono.read() while lap < 1200 file_dati.write(repr(lib_imu.get_euler()[0])) time.sleep(0.02) lap = chrono.read() print("fine") chrono.stop() -
@robert-hh Thank you, I did in this way and the code run, but the real sample isn't 0.02 s but each 0.035 s. And I don't know why?!
-
@vflorio94 Taking the measurement and writing takes time too. Now you know, it's about 0.015s.
-
@robert-hh Thank you very much for your help. I've never scheduled with Python, so for me is very difficult and I have to do this for my master thesis. For me you were very valuable.
thank you. -
@robert-hh Hi, sorry for my insistence. I have a new problem
╝Traceback (most recent call last): File "<stdin>", line 24, in <module> OSError: 28 ╝>but i don't know why, because Yesterday this code run and now it give me this message.
the code is this oneimport machine import pycom from machine import Timer import time import lib_imu from machine import I2C from machine import PWM import gc chrono = Timer.Chrono() lib_imu.set_configmode() time.sleep(0.05) lib_imu.set_units() time.sleep(0.05) lib_imu.set_mode('ndof') # List =[] file_dati = open("datiprova_tempo20.txt", "a") chrono = Timer.Chrono() chrono.start() lap = chrono.read() while lap <= 1200: #eul = lib_imu.get_euler() file_dati.write(repr(lap) + "\t ") file_dati.write(repr(lib_imu.get_euler()[0]) + "\t ") time.sleep(0.02) lap = chrono.read() file_dati.close() print("fine") chrono.stop()Can you help me please?
-
@vflorio94 Error 28 means: "No space left on device"
So your file system is full. You have to delete some files, or better change your code to save on an SD card. The internal flash file system is pretty small. I do not know why, because most of the FiPy's flash is not used. -
@robert-hh I delete each file.txt that I write before on the device with Filezilla.

Yesterday and the day before in this condition I can wrote file.txt on the device, but now I can't and it give me this error.
but on the memory there are only those file.py.
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