Ich werd Wahnsinnig...
Gestern Abend hatte ich alles angeschlossen und es hat Funktioniert und heute will es ums verrecken nicht...
Es geht um das Sketch der mir mit das Flow Signal auswertet:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;
byte ok_pin =3;
byte alarm_pin = 4;
long millis_new;
long millis_old;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
int pot1pin = A7; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int Sollwert; // Variable für den Servo im Bereich 800 bis 2000µs
int val1;
int oldval; // Schwellwert variable
int pot2pin2 = A6; // analog pin used to connect the potentiometer
int val2; // variable to read the value from the analog pin
int Sollwert2; // Variable für den Servo im Bereich 800 bis 2000µs
int val12;
int oldval2; // Schwellwert2 variable
// Intiieren des Timer 1 für Servo-Impulse an Pin 9 und 10
void initServo() {
TIMSK1 = 0; // keine Interrupts
TCCR1A = _BV(WGM11); /* Fast PWM, ICR1 is top */
TCCR1B = _BV(WGM13) | _BV(WGM12) /* Fast PWM, ICR1 is top */
| _BV(CS11) ; // div 8 clock prescaler ( 0,5µs per tic )
OCR1A = 3000; // initiale Pulsbreite 1,5ms
OCR1B = 3000; // initiale Pulsbreite 1,5ms
ICR1 = 40000; // 20ms period
TCCR1A = TCCR1A & ~_BV(COM1A0) | _BV(COM1A1); // Output to pin 9 ( OCRA )
TCCR1A = TCCR1A & ~_BV(COM1B0) | _BV(COM1B1); // Output to pin 10 ( OCRB )
}
// Pulsbreite einstellen ( pos in µs )
void servo1Write(int pos) {
OCR1A = pos*2;
}
void servo2Write(int pos) {
OCR1B = pos*2;
}
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
millis_old=0;
millis_new=0;
pinMode(ok_pin,OUTPUT);
pinMode(alarm_pin,OUTPUT);
// digitalWrite(ok_pin,HIGH);
digitalWrite(alarm_pin,LOW);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pinMode( 9, OUTPUT );
pinMode( 10, OUTPUT );
initServo();
//SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
//Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.setFont(&FreeMonoBoldOblique12pt7b);
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
void loop() {
// Enable the interrupt
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
// put your main code here, to run repeatedly:
analogReference(EXTERNAL);
val = analogRead(pot1pin); // reads the value of the potentiometer (value between 0 and 1023)
Sollwert = map(val>>3, 0, 127, 500, 2500); // scale it to use it with the servo (value between 0 and 180)
if ( abs( Sollwert - oldval) > 45 ) { // <<-- 10 ist hier der Schwellwert
servo1Write(Sollwert); // sets the servo position according to the scaled value
oldval = Sollwert;
}
display.setCursor(10, 20); // Start at top-left corner
// Not all the characters will fit on the display. This is normal.
// Library will draw what it can and the rest will be clipped.
display.clearDisplay();
display.print("MIN ");
// display.setCursor(0, 36); // Start at top-left corner
val1 = map(val, 0, 1023, 0, 100);
display.print(val1); display.print("%");
// put your main code here, to run repeatedly:
analogReference(EXTERNAL);
val2 = analogRead(pot2pin2); // reads the value of the potentiometer (value between 0 and 1023)
Sollwert2 = map(val2>>3, 0, 127, 500, 2500); // scale it to use it with the servo (value between 0 and 180)
if ( abs( Sollwert2 - oldval2) > 45 ) { // <<-- 10 ist hier der Schwellwert
servo2Write(Sollwert2); // sets the servo position according to the scaled value
oldval2 = Sollwert2;
}
display.setCursor(10, 50); // Start at top-left corner
// Not all the characters will fit on the display. This is normal.
// Library will draw what it can and the rest will be clipped.
display.print("MAX ");
// display.setCursor(0, 36); // Start at top-left corner
val12 = map(val2, 0, 1023, 0, 100);
display.print(val12); display.print("%");
display.display();
delay(15);
}
/*
Insterrupt Service Routine
*/
void pulseCounter()
{
millis_new=millis();
if(millis_new-millis_old>50)
{
digitalWrite(ok_pin,LOW);
digitalWrite(alarm_pin,HIGH);
}
else
{
digitalWrite(ok_pin,HIGH);
digitalWrite(alarm_pin,LOW);
}
millis_old=millis();
}
Alles anzeigen
Auf D2 ist der Flow Sensor am Nano angeschlossen auf D3 gibt er raus wenn alles ok ist die 5V High und auf D4 wenn alles ok ist ein Low 0V.
Der D2 Pulsiert schön das hab ich mir auf dem Osci angesehen und auch verglichen mit einem nicht eingebaute Flow Sensor der gibt das Gleiche Signal.
Aber der Nano schaltet nicht um also gibt er mir das Lasernetzteil nicht frei. Klar kann ich das Brücken, will ich aber nicht!!!
An D3 steht 0V an D4 Stehen 5V unverändert, egal ob der Flow da ist oder nicht.
Ich habe alle Werte direkt an den Nano gemessen, näher ran geht es nicht mehr, also direkt auf der Platine.
Ich habe auch die Nanos mal getauscht um auszuschließen ob der Ein- Ausgang kaputt ist...
Gestern hat das funktioniert....... An der Verkabelung wurde nichts gemacht...
Teufel Teufel bin ich sauer.