| 1 |
|
| 2 |
import time |
| 3 |
|
| 4 |
from matplotlib import pyplot as plt |
| 5 |
import numpy as np |
| 6 |
|
| 7 |
|
| 8 |
PIN_SCK = 7; PIN_MOSI = 5 ; PIN_SS = 4 |
| 9 |
|
| 10 |
SPE = 6 ; MSTR = 4 ; SPR0 = 0 |
| 11 |
PORTBvalue = 0 |
| 12 |
|
| 13 |
setReg('DDRB', (1 << PIN_SCK) | (1 << PIN_MOSI) | (1 << PIN_SS)) |
| 14 |
setReg('SPCR', (1 << SPE) | (1 << MSTR)| (1<<SPR0) ) |
| 15 |
|
| 16 |
plt.ion() |
| 17 |
x=[] ; y = [] |
| 18 |
start_time = time.time() |
| 19 |
for a in range(5): |
| 20 |
t = time.time() - start_time |
| 21 |
|
| 22 |
PORTBvalue &= ~(1<<PIN_SS) |
| 23 |
setReg('PORTB', PORTBvalue) |
| 24 |
|
| 25 |
setReg('SPDR', 0xFF) |
| 26 |
time.sleep(0.001) |
| 27 |
v1 = getReg('SPDR') |
| 28 |
|
| 29 |
setReg('SPDR', 0xFF) |
| 30 |
time.sleep(0.001) |
| 31 |
v2 = getReg('SPDR') |
| 32 |
|
| 33 |
PORTBvalue |= (1<<PIN_SS) |
| 34 |
setReg('PORTB', PORTBvalue) |
| 35 |
temp = (v1<<8)|v2 |
| 36 |
if temp&0x4: |
| 37 |
continue |
| 38 |
temp = (temp >>3 )*0.25 |
| 39 |
|
| 40 |
|
| 41 |
print(t,temp) |
| 42 |
plt.scatter(t, temp , s=5) |
| 43 |
x.append(t); y.append(temp) |
| 44 |
plt.pause(0.2) |
| 45 |
print('press any key/button to close') |
| 46 |
np.savetxt('tmp.txt',np.column_stack([x,y]),fmt='%1.2f') |
| 47 |
plt.waitforbuttonpress() |