As you may know the current measuring here was done by measuring AI0, then AI1, and thus doing AI0-AI1 to get the voltage at the resistance and retrieving the current with Ohm's law. It was before implementing this whole circuit to draw the current-voltage characteristic in the negatives too.
But here, my voltages are going to be negative. So I cannot do an analogRead(AI0) or analogRead(AI1) because it's going to damage my analog inputs right? I thought Arduino pins only accepted positive 0-3.3V voltages. Am I mistaken ?
Okay yeah I thought about this but hoped there would be other possibilities.
Thanks! I'll keep you updated with the final schemes and photos of the prototype when everything is finished and working!
You turned R4 back to a 10K res. Do you think that's better ? I thought a smaller resistance like 270 would bring a smaller voltage drop in this branch, meaning I'd enjoy more of my range in my SD pin. Because for the moment, my Up in my SD pin goes from -0.6V to 2.2V
Good news is, I have things that are really close to the actual result I'm supposed to have. But certain plots have very strange faces. For example, manually, I plotted the Chip Select (DAT3) pin and got this :
Then I did it with the arduino and here's the result :
I don't know why there are such discontinuities. Here's the Python script for those interested:
import serial
import matplotlib.pyplot as plt
import numpy as np
# Serial port connection part
port = "COM3"
baudrate = 9600
timeout = 10
ser = serial.Serial(port, baudrate, timeout=timeout)
A0=[]
A1=[]
i=[]
u=[]
val_A1=0
val_A0=0
Ur=[]
n=0
m=0
l=0
while True:
line = ser.readline().decode('utf-8').strip() #read the line from the serial port
pos=0
if line == "": #if there no more lines, break
break
for i in range (len(line)):
if line[pos] == " ": # the space character is used to seperate AI1 and AI0
val_A1=line[0:pos]
val_A0=line[pos+1:]
else:
pos+=1
A0.append(float(val_A0))
A1.append(float(val_A1))
n+=1
print(line)
ser.close()
#re-scaling of the range
for m in range (len(A0)):
Ur.append(-0.0064453125*(A0[m]-A1[m]))
i.append(Ur[m]*1000/270) #current values are in this list
for l in range (len(A1)):
u.append(A1[l]*(-0.0064453125)+3.3) #voltage values are in this list
#plot part
Y=i
X=u
plt.plot(X,Y)
plt.grid()
plt.title("Current-voltage characteristic")
plt.xlabel("Voltage (V)")
plt.ylabel("Intensity (mA)")
plt.show()
Also, I would like to make everything automatic, even the selection of the different pins. I thought I could use a multiplexer that is connected to all the different entrys and redirects the entry of only 1 pin, waits for the current-voltage characteristic to be drawn, then goes onto the next one... I'm going to see what different choices I have with these components and how they work. Never used one I don't know if that's even possible or if it's just going to work digitally