Hallo Zusammen.
Ich hoffe ihr könnt mir helfen. Ich habe mich, nach guten Erfahrungen mit einem Atmega32 mal an einen Arduino gewagt, da ich etwas sehr klein gebautes brauche.
Nun habe ich die Funktion von "serial.print" ausprobiert und musste nach dem Hochladen des Sketches feststellen, dass Arduino IDE nicht mehr reagierte.
Leider auch der Nano nicht mehr.
Und zu guter letzt kann ich nicht einmal mehr einen neuen Sketch hochladen.
Genutzt wird ein Arduino Nano 33 BLE mit Arduino IDE.
Da ich noch am Testen bin, wie ich etwas nutze, ist der Code natürlich voller Kommentare.
Hello everyone.
I hope you can help me. After good experiences with an Atmega32, I dared to use an Arduino because I needed something very small.
Now I have tried the function of "serial.print" and after uploading the sketch I discovered that the Arduino IDE no longer responded.
Unfortunately, the Nano no longer either.
Finally, I can't even upload a new sketch anymore.
An Arduino Nano 33 BLE with Arduino IDE is used.
Since I'm still testing how to use something, the code is of course full of comments.
/*
This is an example on how to use the 1.8" TFT 128x160 SPI ST7735 display using the Adafruit library.
ST7735 TFT SPI display pins for Arduino Uno/Nano:
* LED = 3.3V
* SCK = 13
* SDA = 11
* A0 = 8
* RESET = 9
* CS = 10
* GND = GND
* VCC = 3.3V
Hardware SPI Pins:
* Arduino Uno SCK=13, SDA=11
* Arduino Nano SCK=13, SDA=11
* Arduino Due SCK=76, SDA=75
* Arduino Mega SCK=52, SDA=51
SPI pin names can be confusing. These are the alternative names for the SPI pins:
MOSI = DIN = R/W = SDO = DI = SI = MTSR = SDA = D1 = SDI
CS = CE = RS = SS
DC = A0 = DO = DOUT = SO = MRST
RESET = RST
SCLK = CLK = E = SCK = SCL = D0
Reference page for GFX Library: https://cdn-learn.adafruit.com/downloads/pdf/adafruit-gfx-graphics-library.pdf
Color is expressed in 16 bit with Hexadecimal value.
To select a particular color, go here and copy the "Hexadecimal 16 bit color depth value":
https://ee-programming-notepad.blogspot.com/2016/10/16-bit-color-generator-picker.html
Common colors:
* BLACK 0x0000
* BLUE 0x001F
* RED 0xF800
* GREEN 0x07E0
* CYAN 0x07FF
* MAGENTA 0xF81F
* YELLOW 0xFFE0
* WHITE 0xFFFF
A way to select a color is to write: "ST7735_BLACK", or "ST7735_BLUE", etc.
Or just write the code for the color. Either way, it works.
List of custom fonts: https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts
Note about custom font:
* Text background color is not supported for custom fonts. For these reason you would need to draw a filled
rectangle before drawing the text. But this would cause the text to flicker, so I don't recommend using custom fonts
for components that refresh continuously.
* Using custom fonts slows down the arduino loop, so the refresh rate is lesser than using the standard font.
Sketch made by: InterlinkKnight
Last modification: 01/11/2018
*/
#include <Adafruit_GFX.h> // Include core graphics library
#include <Adafruit_ST7735.h> // Include Adafruit_ST7735 library to drive the display
// Declare pins for the display:
#define TFT_CS 10
#define TFT_RST 9 // You can also connect this to the Arduino reset in which case, set this #define pin to -1!
#define TFT_DC 8
// The rest of the pins are pre-selected as the default hardware SPI for Arduino Uno (SCK = 13 and SDA = 11)
//Declare Pins für RGB-LED
#define RED 22
#define GREEN 23
#define BLUE 24
// Create display:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
//#include <Fonts/FreeSerif18pt7b.h> // Add a custom font
uint16_t width(128); //Breite
uint16_t height(160); //Hoehe
int Variable1; // Create a variable to have something dynamic to show on the display
int Variable2;
int Variable3;
int Button_Counter;
// constants won't change. They're used here to set pin numbers:
const byte Pin_Button = 7; // the number of the pushbutton pin
const byte Pin_Signal = 2; // the number of the pushbutton pin
// variables will change:
int State_Button = 0; // variable for reading the pushbutton status
int State_Signal = 0;
int State_LED = 0;
long Timer1 = 0;
long Timeout1 = 500;
/*
Frequenzzähler
Gibt die Frequenz des Spannungsignals an Pin 7 aus
*/
unsigned long T; //Periodendauer in us
unsigned long T2; //Periodendauer in s
double f;
void setup() // Start of setup
{
Serial.begin(9600);
// initialize the LED pin as an output:
//pinMode(LED_BUILTIN, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(Pin_Button, INPUT);
pinMode(Pin_Signal, INPUT);
// Display setup:
// Use this initializer if you're using a 1.8" TFT
tft.initR(INITR_BLACKTAB); // Initialize a ST7735S chip, black tab
tft.fillScreen(ST7735_BLACK); // Fill screen with black
tft.setRotation(0); // Set orientation of the display. Values are from 0 to 3. If not declared, orientation would be 0,
// which is portrait mode.
tft.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
// with setTextWrap(true).
// We are going to print on the display everything that is static on the setup, to leave the loop free for dynamic elements:
tft.setCursor(0, 43); // Set position (x,y)
tft.setTextColor(ST7735_WHITE); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(2); // Set text size. Goes from 0 (the smallest) to 20 (very big)
tft.println("Verbrauch"); // Print a text or value
tft.setCursor(99, 63); // Set position (x,y)
tft.setTextColor(ST7735_WHITE); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(2); // Set text size. Goes from 0 (the smallest) to 20 (very big)
tft.println("l"); // Print a text or value
//Draw line:
tft.drawLine(83, 80, 124, 80, ST7735_WHITE); // Draw line (x0,y0,x1,y1,color)
tft.setCursor(87, 83); // Set position (x,y)
tft.setTextColor(ST7735_WHITE); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(2); // Set text size. Goes from 0 (the smallest) to 20 (very big)
tft.println("min"); // Print a text or value
tft.setCursor(0, 0); // Set position (x,y)
tft.setTextColor(ST7735_WHITE); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(2); // Set text size. Goes from 0 (the smallest) to 20 (very big)
tft.println("Reichweite"); // Print a text or value
//Draw line: (Senkrecht)
tft.drawLine(103, 63, 103, 97, ST7735_WHITE); // Draw line (x0,y0,x1,y1,color)
} // End of setup
void loop() // Start of loop
{
// if (millis() > Timeout1 + Timer1 ) {
// Timer1 = millis();
//
// if (State_LED == LOW)
// {
// State_LED = HIGH;
// digitalWrite(GREEN, HIGH);
// }
// else
// {
// State_LED = LOW;
// digitalWrite(GREEN, LOW);
// }
// }
T = pulseIn(Pin_Signal, HIGH) + pulseIn(Pin_Signal, LOW);
if (T==0)
{
Serial.println("Timeout.");
}
else
{
f=1/(double)T; // f=1/T
}
T2 = T / 1000000;
Serial.print(f*1e6); //Ausgabe in Hertz
Serial.print(" Hz; ");
Serial.print(T/1000); //Ausgabe in µs
Serial.print(" ms; ");
Serial.print(1/T2, 3); //Ausgabe in ml/s
Serial.print((1/(T2/10500))/1000, 3); //Ausgabe in ml/s
Serial.print(" ml/s; ");
Serial.print((1/(T/1000/105))*600, 3); //Ausgabe in l/min
Serial.println(" l/min");
State_Signal = digitalRead(Pin_Signal);
if (State_Signal == LOW)
{
// turn LED on:
digitalWrite(BLUE, HIGH);
Serial.println("Signal an");
}
else
{
// turn LED off:
digitalWrite(BLUE, LOW);
//Serial.println("Signal aus");
}
State_Button = digitalRead(Pin_Button);
if (State_Button == LOW)
{
// turn LED on:
digitalWrite(RED, LOW);
Button_Counter++;
}
else
{
// turn LED off:
digitalWrite(RED, HIGH);
}
if (Button_Counter == 0)
{
Variable1 = 8;
Variable2 = 1;
}
else if (Button_Counter == 1)
{
Variable1 = 88;
Variable2 = 2;
}
else if (Button_Counter == 2)
{
Variable1 = 888;
Variable2 = 3;
}
else if (Button_Counter == 3)
{
Variable1 = 8888;
Variable2 = 4;
}
else if (Button_Counter == 4)
{
Variable1 = 888;
Variable2 = 5;
}
else if (Button_Counter == 5)
{
Variable1 = 88;
Variable2 = 6;
}
else
{
Button_Counter = 0;
}
if(Variable3 > 150) // If Variable1 is greater than 150
{
Variable3 = 0; // Set Variable1 to 0
}
else
{
Variable3++; // Increase variable by 1
}
// We are going to print on the display everything that is dynamic on the loop, to refresh continuously:
// Write to the display the Variable1 with right text alignment:
if (Variable1 <= 9)
{
tft.setCursor(63, 70); // Set position (x,y)
tft.fillRect(9, 70, 51, 21, ST7735_RED); // Draw filled rectangle (x,y,width,height,color)
}
else if (Variable1 <= 99)
{
tft.setCursor(45, 70); // Set position (x,y)
tft.fillRect(9, 70, 33, 21, ST7735_GREEN); // Draw filled rectangle (x,y,width,height,color)
}
else if (Variable1 <= 999)
{
tft.setCursor(27, 70); // Set position (x,y)
tft.fillRect(9, 70, 15, 21, ST7735_BLUE); // Draw filled rectangle (x,y,width,height,color)
}
else if (Variable1 <= 9999)
{
tft.setCursor(9, 70); // Set position (x,y)
}
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(3); // Set text size. Goes from 0 (the smallest) to 20 (very big)
tft.println(Variable1); // Print a text or value
tft.setCursor(83, 127); // Set position (x,y)
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(2); // Set text size. Goes from 0 (the smallest) to 20 (very big)
tft.println(Variable2); // Print a text or value
tft.setCursor(13, 107); // Set position (x,y)
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(2); // Set text size. Goes from 0 (the smallest) to 20 (very big)
tft.println(Variable3); // Print a text or value
} // End of loop
// Draw rectangle:
//tft.drawRect(0, 60, 60, 30, ST7735_CYAN); // Draw rectangle (x,y,width,height,color)
// It draws from the location to down-right
// Draw rounded rectangle:
//tft.drawRoundRect(68, 60, 60, 30, 10, ST7735_CYAN); // Draw rounded rectangle (x,y,width,height,radius,color)
// It draws from the location to down-right
// Draw triangle:
//tft.drawTriangle(60,120, 70,94, 80,120, ST7735_YELLOW); // Draw triangle (x0,y0,x1,y1,x2,y2,color)
// Draw filled triangle:
//tft.fillTriangle(100,120, 110,94, 120,120, ST7735_CYAN); // Draw filled triangle (x0,y0,x1,y1,x2,y2,color)
// Draw line:
//tft.drawLine(0, 125, 127, 125, ST7735_CYAN); // Draw line (x0,y0,x1,y1,color)
// Draw circle:
//tft.drawCircle(15, 144, 14, ST7735_GREEN); // Draw circle (x,y,radius,color)
// Draw a filled circle:
//tft.fillCircle(60, 144, 14, ST7735_BLUE); // Draw circle (x,y,radius,color)
// Draw rounded rectangle and fill:
//tft.fillRoundRect(88, 130, 40, 27, 5, 0xF81B); // Draw rounded filled rectangle (x,y,width,height,color)
Nun hatte ich schon versucht einen leeren Sketch hochzuladen.
Now I had already tried to upload an empty sketch.
(...)
Der Sketch verwendet 83440 Bytes (8%) des Programmspeicherplatzes. Das Maximum sind 983040 Bytes.
Globale Variablen verwenden 43920 Bytes (16%) des dynamischen Speichers, 218224 Bytes für lokale Variablen verbleiben. Das Maximum sind 262144 Bytes.
Erzwinge Reset durch öffnen/schließen mit 1200 bps auf dem Port COM3
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
PORTS {COM3, } / {COM3, } => {}
Uploading using selected port: COM3
C:\Users\Daniel\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.9.1-arduino2/bossac.exe -d --port=COM3 -U -i -e -w C:\Users\Daniel\AppData\Local\Temp\arduino_build_909278/sketch_jul27a.ino.bin -R
Beim Hochladen des Sketches ist ein Fehler aufgetreten
processing.app.SerialException: Fehler beim Öffnen des seriellen Ports "COM3".
at processing.app.Serial.<init>(Serial.java:152)
at processing.app.Serial.<init>(Serial.java:82)
at processing.app.SerialMonitor$2.<init>(SerialMonitor.java:132)
at processing.app.SerialMonitor.open(SerialMonitor.java:132)
at processing.app.AbstractMonitor.resume(AbstractMonitor.java:132)
at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2120)
at processing.app.Editor.access$1300(Editor.java:117)
at processing.app.Editor$UploadHandler.run(Editor.java:2089)
at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - COM3; Method name - openPort(); Exception type - Port busy.
at jssc.SerialPort.openPort(SerialPort.java:164)
at processing.app.Serial.<init>(Serial.java:141)
... 8 more
Fehler beim Öffnen des seriellen Ports "COM3".
Und nun stehe ich da. Kann ich irgendwie denn Sketch löschen. Oder liegt gar ein ganz anderes Problem vor?
Die Probleme starteten mit diesen Zeilen:
Serial.print(1/T2, 3); //Ausgabe in ml/s
Serial.print((1/(T2/10500))/1000, 3); //Ausgabe in ml/s
Serial.print(" ml/s; ");
Serial.print((1/(T/1000/105))*600, 3); //Ausgabe in l/min
Serial.println(" l/min");
And now I stand there. Can I somehow delete the sketch. Or is there a completely different problem?
The problems started with these lines:
Serial.print(1/T2, 3); //Ausgabe in ml/s
Serial.print((1/(T2/10500))/1000, 3); //Ausgabe in ml/s
Serial.print(" ml/s; ");
Serial.print((1/(T/1000/105))*600, 3); //Ausgabe in l/min
Serial.println(" l/min");