data write speeds and broken SD cards
Re: data write speeds and broken SD cards
Just finished the SMT rework to mount the ADXL375. Nasty work, even with professional equipment. But it works, at the first try! I did not even have to change the code, as both ADXLs are nearly identical interface-wise.
- Attachments
-
- untitled.jpg (53.41 KiB) Viewed 6064 times
Re: data write speeds and broken SD cards
Hi,
I know this a very old thread, but I find it still very useful.
I've been looking at the ADXL345 data using the I2C interface, but the SPI interface you use here seems better.
Would you mind sharing the ADXL SPI code?
Thanks
I know this a very old thread, but I find it still very useful.
I've been looking at the ADXL345 data using the I2C interface, but the SPI interface you use here seems better.
Would you mind sharing the ADXL SPI code?
Thanks
Re: data write speeds and broken SD cards
Now this was four years ago... I really don't remember much about that project!
I dug out this code:
- Martin
I dug out this code:
Code: Select all
# main.py -- put your code here!
#INT1: Y4
#INT2: Y3
#/CS: Y5
#SDO: Y8
#SDA: Y7
#SCL: Y6
import os
import pyb
from pyb import SPI
CMD_ID = bytearray((0x80,0)) #read device ID
#write BW_RATE, max speed, POWER_CTL measure=1, interrupts enabled watermark,16g
CMD_INI = bytearray((0x6C,0x0f,0x08,2,0,0,0b00001011))
CMD_INI2 = bytearray((0x38,0b01010100)) #watermark interrupt at 20 samples
#read six acceleration bytes (X0 X1 Y0 Y1 Z0 Z1)
CMD_RD = bytearray((0xF2,0,0,0,0,0,0))
b2=bytearray(2)
b7=bytearray(7)
#init interrupt pins as input
int1pin=pyb.Pin.board.Y4
int2pin=pyb.Pin.board.Y3
int1pin.init(pyb.Pin.IN)
int2pin.init(pyb.Pin.IN)
# Chip select (not used by driver!)
nCS=pyb.Pin(pyb.Pin.board.Y5,pyb.Pin.OUT_PP)
nCS.high()
spi = SPI(2, SPI.MASTER, baudrate=5000000, polarity=1, phase=1,firstbit=SPI.MSB)
#query ID
nCS.low();spi.send_recv(CMD_ID,b2);nCS.high()
#print(b2)
# Initialize accelerometer
nCS.low();spi.send(CMD_INI);nCS.high()
nCS.low();spi.send(CMD_INI2);nCS.high()
#pyb.delay(20) #1 ms delay
f=open('/sd/test.bin','wb')
# wait for FiFo to be filled
for k in range(160*5):
while int1pin.value()==False:
pass
# read 20 values and write to SD card
for i in range(20):
nCS.low();spi.send_recv(CMD_RD,b7);nCS.high()
f.write(b7)
f.close()
-
- Posts: 7
- Joined: Fri Jun 07, 2019 10:05 pm
Re: data write speeds and broken SD cards
This is great work! I am also trying to make a data logger with an ADXL375 for my mountain bike. I spent a lot of time writing a driver although I can't get it quite correct. I think that I am interpreting the data incorrectly. Would you be willing to share your ADXL375 driver?
Re: data write speeds and broken SD cards
There is no "driver". The code I published does all the interfacing.
I used a matlab script to display the results:
I also attached one sample file.
- Martin
I used a matlab script to display the results:
Code: Select all
fileID = fopen('test.bin');
A = fread(fileID);
fclose(fileID)
A=reshape(A,7,[]);
x=A(2,:)+256*A(3,:);
y=A(4,:)+256*A(5,:);
z=A(6,:)+256*A(7,:);
for i=1:length(x)
if x(i)>32767
x(i)=x(i)-65536;
end
if y(i)>32767
y(i)=y(i)-65536;
end
if z(i)>32767
z(i)=z(i)-65536;
end
end
sc=49e-3;
x=x*sc;y=y*sc;z=z*sc;
t=(1:length(x))/3200;
plot(t,x,t,y,t,z)
legend('x','y','z')
grid on;
xlabel('Time (s)')
ylabel('Acceleration (g)')
title('ADXL375 acceleration logger');
- Martin
- Attachments
-
- test.zip
- (44.29 KiB) Downloaded 220 times
- rcolistete
- Posts: 352
- Joined: Thu Dec 31, 2015 3:12 pm
- Location: Brazil
- Contact:
Re: data write speeds and broken SD cards
See the MicroPython forum topic "Convert float to hex string" and Pycom forum topic "Bytearray() and structures for floating point values".blmorris wrote: ↑Fri Sep 12, 2014 3:47 pmHowever, there is a problem passing floating point objects to 'bytes()' which I found after my last post; I tried to pass a list of floats to bytes() the same way that you did and the file just didn't look right. It seems that bytes() really only accepts list of 8-bit integers (either decimal or hex strings) or ASCII characters and escape sequences (I'm probably not getting this exactly right…)
When another type of object is passed to bytes(), only a single byte gets stored; I suspect that this single byte may be the low-order byte of the pointer to that object, but I'm not certain of this.
You may need to figure out a way to convert your floats to integers or just go ahead with storing strings anyway. There must be a way to convert the 32-bit value from a float to a set of 4 bytes, but I haven't found it yet.
...
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).
-
- Posts: 7
- Joined: Fri Jun 07, 2019 10:05 pm
Re: data write speeds and broken SD cards
I have been trying to get similar speeds using an Adafruit microSD card breakout board and the sdcard.py driver from GitHub https://github.com/micropython/micropyt ... /sdcard.py
My test code is as follows:
Code: Select all
READ_COMMAND = bytearray((0x32,0,0,0,0,0,0))
data1 = bytearray(7)
def speedTest():
startTime = utime.ticks_us()
# ~30ms
file = open('/sd/log.bin', 'wb')
for k in range(20):
# ~0.13ms
SPI2_CS1.low(); spi_2.send_recv(READ_COMMAND, data1); SPI2_CS1.high()
# ~0.053ms
file.write(data1)
# ~25ms
file.close()
deltaTime = utime.ticks_diff(utime.ticks_us(), startTime)
print(deltaTime/1000000)
The only thing that I can think of at this point is that the sdcard.py driver is much slower than what you were using? Is there a built-in SD driver that uses SDIO and allows for much faster speeds?
Any thoughts are much appreciated!