Würde ich auch begrüßen. Und dann eventuell diesen Thread hier aufteilen. Ist ja mittlerweile total OT2Alf20658 hat geschrieben:Ja gut, ich habe es lieber wenn ich keinen Taschenrechner als Begleittechnik brauche.
Aber ich muss mich erstmal einarbeiten. Die erste Technik für Arduino ist schon aus China unterwegs.
An ADMIN:
Hallo Andreas, vieleicht wäre ja noch `Elektronik ` als Thema einzubauen ?
Hallo Forum, Vorstellung und ZPM2000DQT
-
Waldmensch
Re: Hallo Forum, Vorstellung und ZPM2000DQT
-
Waldmensch
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Update zum Code. Es sind ein Haufen Compilerdirektiven dazugekommen mit denen man den Code anpassen kann. Enthalten ist jetzt ein I2C push, der die erfaßten Daten auf einen I2C Slave schiebt. Der Strommesser über Shunt ist auch drin. Ich habe noch ein headerfile für ein paar nützliche I2C Funktionen eingefügt. Dieses File wird aber aktuell nicht benötigt solange #define IS_I2C_MASTER auskommentiert ist. Da man die SD Karte auch an den I2C Slave anschließen könnte, habe ich die Funktionalität ebenfalls abschaltbar gemacht (#define LOCAL_SD_CARD) Der Code sollte sich so nutzen lassen. Ausgelegt ist er für einen Arduino nano 3.0. Bei anderen Arduinos sind eventuell die Analogpins anzupassen.
Pin 19 - Temperaturfühler
Pin 20, 21, 22, 23 - Batteriespannungen
Pin 24 - Strommessung / Shunt
Die Debugausgabe sieht jetzt so aus - immer noch ohne Außenbeschaltungen. Deshalb sind die Werte wirr
Pin 19 - Temperaturfühler
Pin 20, 21, 22, 23 - Batteriespannungen
Pin 24 - Strommessung / Shunt
Code: Alles auswählen
#include <SPI.h>
#include <SD.h>
#define DEBUG
// uncomment if you want to push data to a I2C Slave
//#define IS_I2C_MASTER
// uncomment if you use a local display
#define LOCAL_DISPLAY
// uncomment if you use a local SD Card
#define LOCAL_SD_CARD
// uncomment if you use a shunt for current mesure
#define CURRENT
#define NUM_BATTERYS 4
#define VOLTAGE 5.0
#define REFRESH 1000
#ifdef LOCAL_SD_CARD
#define SD_RETRY 60
#endif
#ifdef IS_I2C_MASTER
#include <Wire.h>
#include "I2C_Anything.h"
#define MAXVALUES 6
#endif
// used Pins Temperature
int sensorPinTemperature = 19; //the analog pin the TMP36's Vout (sense) pin is connected to the resolution is 10 mV / degree centigrade with a 500 mV offset to allow for negative temperatures
float temperatureC;
#ifdef CURRENT
// used Pins Current (shunt)
int sensorPinCurrent = 24;
float currentA;
#endif
// used Pins Batterys
int SensorPinBattery[] = {20, 21, 22, 23};
float vin[NUM_BATTERYS];
// resistance of R1 & R2
float R1 = 13000.0;
float R2 = 4300.0;
#ifdef IS_I2C_MASTER
float values[MAXVALUES];
const byte SLAVE_ADDRESS = 42;
#endif
#ifdef LOCAL_SD_CARD
// chipselect Pin for SD card
const int chipSelect = 10;
int sdCardPresent = 0;
String filename = "batlog";
int sdCardInitCount = SD_RETRY;
#endif
int measureCount = 0;
void setup()
{
#ifdef IS_I2C_MASTER
Wire.begin(); // join i2c bus as Master
for (int i = 0; i < MAXVALUES; i++)
{
values[i] = 0.0;
}
#endif
// Set Pinmode for Temperature Sensor
pinMode(sensorPinTemperature, INPUT);
// Set Pinmode for Battery Sensors
for (int i = 0; i < NUM_BATTERYS; i++)
{
pinMode(SensorPinBattery[i], INPUT);
}
#ifdef CURRENT
pinMode(sensorPinCurrent, INPUT);
#endif
Serial.begin(9600); //Start the serial connection with the computer to view the result open the serial monitor
while (!Serial) {
; /* wait for serial port to connect. Needed for Leonardo only*/
}
#ifdef LOCAL_SD_CARD
// Set Pinmode for SD Card chipselect
pinMode(chipSelect, OUTPUT);
initSDCard();
#endif
}
void loop()
{
// set BatteryArray and Temperature to 0.0 and raise measure count with 1
resetValues();
// make a string for assembling the data to log:
String dataString = String(measureCount);
// get Temperature and write to string
getTemperature();
dataString += ";" + String(temperatureC);
#ifdef IS_I2C_MASTER
values[0] = temperatureC;
#endif
// go through the batterys and write the voltage
for (int i = 0; i < NUM_BATTERYS; i++)
{
getBatteryVoltage(i);
dataString += ";" + String(vin[i]);
#ifdef IS_I2C_MASTER
values[i + 1] = vin[i];
#endif
}
#ifdef CURRENT
getCurrent();
dataString += ";" + String(currentA);
#ifdef IS_I2C_MASTER
values[5] = currentA;
#endif
#endif
#ifdef LOCAL_DISPLAY
// write to display
writeToDisplay();
#endif
#ifdef LOCAL_SD_CARD
// just in case we have no card
reinitSDCard();
// write the values to SD Card
writeToSDCard(dataString);
#endif
#ifdef IS_I2C_MASTER
sendI2Cdata();
#endif
// wait for next interval
delay(REFRESH);
}
#ifdef LOCAL_SD_CARD
void writeCSVHeadline()
{
// write csv head
String dataStringHeadline = "Count;Temperature";
for (int i = 0; i < NUM_BATTERYS; i++)
{
dataStringHeadline += ";Battery" + String(i);
}
writeToSDCard(dataStringHeadline);
}
void reinitSDCard()
{
if (SD_RETRY > 0)
{
if (!sdCardPresent)
{
if( sdCardInitCount <= 0)
{
sdCardInitCount = SD_RETRY;
initSDCard();
}
else
{
sdCardInitCount--;
}
}
}
}
void initSDCard()
{
#ifdef DEBUG
Serial.println("Initializing SD card...");
#endif
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect))
{
#ifdef DEBUG
Serial.println("Card failed, or not present");
#endif
sdCardPresent = 0;
}
else {
#ifdef DEBUG
Serial.println("Card initialized.");
#endif
sdCardPresent = 1;
// generate the next free filename
for(int i = 1;; i++)
{
String temp = filename;
temp.concat(i);
temp.concat(".csv");
char _filename[temp.length()+1];
temp.toCharArray(_filename, sizeof(_filename));
if(!SD.exists(_filename))
{
filename = temp;
break;
}
}
#ifdef DEBUG
Serial.println("Filename for this Session set to: " + filename);
#endif
writeCSVHeadline();
}
}
void writeToSDCard(String line)
{
// If SD Card is properly initialized
if (sdCardPresent)
{
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
String temp = filename;
char _filename[temp.length()+1];
temp.toCharArray(_filename, sizeof(_filename));
File dataFile = SD.open(_filename, FILE_WRITE);
// if the file is available, write to it:
if (dataFile)
{
dataFile.println(line);
dataFile.close();
}
else
{
#ifdef DEBUG
Serial.println("Error opening " + filename);
#endif
sdCardPresent = 0;
}
}
// print to the serial port anyway
Serial.println("Write SD Card: " + line);
}
#endif
#ifdef LOCAL_DISPLAY
void writeToDisplay()
{
// later usage
}
#endif
void resetValues()
{
measureCount++;
temperatureC = 0.0;
for (int i = 0; i < NUM_BATTERYS; i++)
{
vin[i] = 0.0;
}
#ifdef DEBUG
Serial.println("Values reset and count set to " + String(measureCount));
#endif
}
void getTemperature()
{
temperatureC = (((analogRead(sensorPinTemperature) * (float)VOLTAGE) / 1024.0) - 0.5) * 100;
#ifdef DEBUG
Serial.println("Got Temperature at Pin " + String(sensorPinTemperature) + " with " + String(temperatureC) + "C");
#endif
}
void getBatteryVoltage(int numberBattery)
{
vin[numberBattery] = ((analogRead(SensorPinBattery[numberBattery]) * (float)VOLTAGE) / 1024.0) / (R2/(R1+R2));
#ifdef DEBUG
Serial.println("Got Battery " + String(numberBattery) + " at Pin " + String(SensorPinBattery[numberBattery]) + " with " + String(vin[numberBattery]) + "V");
#endif
}
#ifdef CURRENT
float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void getCurrent()
{
int readAmpsADC = analogRead(sensorPinCurrent);
currentA = fabs(fmap(readAmpsADC, 0.0, 1023.0, 0.01, 5.0));
currentA = currentA * 10;
#ifdef DEBUG
Serial.println("Got Current at Pin " + String(sensorPinCurrent) + " with " + String(currentA) + "A");
#endif
}
#endif
#ifdef IS_I2C_MASTER
// http://forum.arduino.cc/index.php?topic=104732.0
void sendI2Cdata()
{
for (byte i = 0; i < MAXVALUES; i++)
{
Serial.println("loop");
Wire.beginTransmission(SLAVE_ADDRESS);
Serial.println("begin tranmission");
I2C_writeAnything(i);
I2C_writeAnything(values[i]);
Serial.println("transmitted");
if (Wire.endTransmission () == 0)
{
#ifdef DEBUG
Serial.println("Wire Send " + String(i) + " value " + String(values[i]));
#endif
}
else
{
#ifdef DEBUG
Serial.println("I2C Error");
#endif
}
delayMicroseconds(2);
}
}
#endif
Die Debugausgabe sieht jetzt so aus - immer noch ohne Außenbeschaltungen. Deshalb sind die Werte wirr
Code: Alles auswählen
Values reset and count set to 1288
Got Temperature at Pin 19 with 59.38C
Got Battery 0 at Pin 20 with 4.64V
Got Battery 1 at Pin 21 with 4.54V
Got Battery 2 at Pin 22 with 4.77V
Got Battery 3 at Pin 23 with 4.77V
Got Current at Pin 24 with 11.71A
Write SD Card: 1288;59.38;4.64;4.54;4.77;4.77;11.71
Values reset and count set to 1289
Got Temperature at Pin 19 with 59.38C
Got Battery 0 at Pin 20 with 4.64V
Got Battery 1 at Pin 21 with 4.48V
Got Battery 2 at Pin 22 with 4.71V
Got Battery 3 at Pin 23 with 4.71V
Got Current at Pin 24 with 11.61A
Write SD Card: 1289;59.38;4.64;4.48;4.71;4.71;11.61
Values reset and count set to 1290
Got Temperature at Pin 19 with 59.38C
Got Battery 0 at Pin 20 with 4.60V
Got Battery 1 at Pin 21 with 4.50V
Got Battery 2 at Pin 22 with 4.77V
Got Battery 3 at Pin 23 with 4.75V
Got Current at Pin 24 with 11.66A
Write SD Card: 1290;59.38;4.60;4.50;4.77;4.75;11.66
Values reset and count set to 1291
Got Temperature at Pin 19 with 58.89C
Got Battery 0 at Pin 20 with 4.66V
Got Battery 1 at Pin 21 with 4.52V
Got Battery 2 at Pin 22 with 4.73V
Got Battery 3 at Pin 23 with 4.71V
Got Current at Pin 24 with 11.61A
Write SD Card: 1291;58.89;4.66;4.52;4.73;4.71;11.61
Values reset and count set to 1292
-
Waldmensch
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Heute sind die Panelmeter gekommen. Das waren die letzten Maße die mir noch für die CAD gefehlt haben. Also ab auf die Fräse und gleich mal zusammengebaut. Die Schalter dienen nur dazu die Panelmeter einzuschalten - ganz schön mächtig aber naja. Die Bananenbuchsen - klar - für Einzelladung. Neben den Schaltern sind noch Mono Klinkenbuchsen um später den Logger anzuschließen.
-
Waldmensch
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Verkabelung und Einbau. Schicker als das olle Werkzeug allemal 
-
Waldmensch
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Leider sieht es auf dem Foto nicht so gut aus wie in echt - der Flux Kompensator 
- MEroller
- Moderator
- Beiträge: 19407
- Registriert: Mo 1. Nov 2010, 22:37
- Roller: Zero S 11kW ZF10.5/erider Thunder (R.I.P)
- PLZ: 7
- Tätigkeit: Entwickler (Traktionsbatterie)
- Kontaktdaten:
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Saubere Sache! Und die Schalter erst 
Zero S 11kWZF10.5
e-rider Thunder 5000: Ruht in Frieden
e-rider Thunder 5000: Ruht in Frieden
-
Waldmensch
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Ick weeeß! Jeder von Denen könnte als Hauptschalter für den Roller dienenMEroller hat geschrieben:Saubere Sache! Und die Schalter erst
-
Waldmensch
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Nebenbei, das mit dem Datenlogger wird nicht gehen wie ich mir das vorgestellt hab (Spannungsteiler über jeder Batterie) Ein befreundeter Elektroniker hat zum Glück Veto eingelegt. Ich muß 4 unterschiedliche Spannungsteiler bauen. Jeweils zwischen Fahrzeugmasse und der zu messenden Batterie. D.h. ich muß rechnen an der ersten Batterie mit 14,4V, an der 2. Batterie mit 28,8V usw. Dann jeweils im Code von der gemessenen Spannung die Spannung der vorherigen Batterie(n) abziehen. Das wird bestimmt spannend. Sobald der Shunt da ist und die SD Kartenleser gehts los.
- MEroller
- Moderator
- Beiträge: 19407
- Registriert: Mo 1. Nov 2010, 22:37
- Roller: Zero S 11kW ZF10.5/erider Thunder (R.I.P)
- PLZ: 7
- Tätigkeit: Entwickler (Traktionsbatterie)
- Kontaktdaten:
Re: Hallo Forum, Vorstellung und ZPM2000DQT
Jaja, Shunts für unsere Fahrzeuge sind richtige Mords-Trümmer, keine Spielsachen mehr wie bei Pedelcs und so 
Zero S 11kWZF10.5
e-rider Thunder 5000: Ruht in Frieden
e-rider Thunder 5000: Ruht in Frieden
Wer ist online?
Mitglieder in diesem Forum: jacko, Semrush [Bot] und 18 Gäste