Serielle Schnittstelle bedienen für Debugging




Alle allgemeinenen Fragen können hier gestellt werden

Serielle Schnittstelle bedienen für Debugging

Beitragvon christian » Fr 12. Jan 2018, 12:41

Hey Ravi,

hier mal eine Beschreibung wie man die serielle Schnittstelle zurücklesen kann, was beim Debugging helfen kann: In der Arduino-SW kannst du unter Werkzeuge->Serieller Monitor dir alle vom Controller gesendeten Zeichen anzeigen lassen.

In Oben im Code musst du einmal den Header inkludieren mittels #include <SoftwareSerial.h>. In der setup-routine kannst du mit Serial.begin(9600); die serielle Schnittstelle starten und nachher mittels Serial.print(“text in gleicher Zeile“); und Serial.println("text in neuer Zeile"); einen Text zurückgeben lassen. Mittels Serial.println(variable); kannst du auch einen Variablenwert ausgeben lassen, was oft hilft.

Hier ist noch der Beispielcode für meine Tonausgabe, wie ich dort eine Einfache Bedienung der Schnittstelle vornehme:


#include <Arduino.h>
#include <JQ6500_Serial.h>
#include <SoftwareSerial.h>

// Create the mp3 module object,
// Arduino Pin 8 is connected to TX of the JQ6500
// Arduino Pin 9 is connected to one end of a 1k resistor,
// the other end of the 1k resistor is connected to RX of the JQ6500
// If your Arduino is 3v3 powered, you can omit the 1k series resistor
int pinSoundIn = 8;
int pinSoundOut = 9;

JQ6500_Serial mp3(pinSoundIn,pinSoundOut);

const int buttonPin = 2;

int buttonState = 0;



typedef enum {ATHMO1=1,ATHMO2,ATHMO3,START,END,GOAL,FASTBALL,MATCHBALL,OVER,TOPOVER,GASP,BAM,SOUNDCOUNT} sound_type; //SOUNDCOUNT ist counter
//sound_type i;
int i = 1;

void runSound(sound_type snd, int vol)
{
mp3.pause();
if (vol>30)
{
vol = 30;
}
mp3.setVolume(vol); // set volume (1-30)
mp3.playFileByIndexNumber(snd); //play file by given index, if it exists

}

void initSound(int pinSoundIn,int pinSoundOut)
{
//JQ6500_Serial mp3(pinSoundIn,pinSoundOut);
mp3.begin(9600); //start 9600Khz
mp3.reset(); //reset chip
mp3.setLoopMode(MP3_LOOP_ONE_STOP); //no looping
}

void setup() {
Serial.begin(9600);
initSound(pinSoundIn,pinSoundOut);
pinMode(buttonPin, INPUT_PULLUP);
Serial.println("setup completed");
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW)
{
Serial.println("buttonState == low registered");
runSound(i,15);
Serial.print("Play sound ");
switch(i)
{
case ATHMO1: Serial.println("ATHMO1"); break;
case ATHMO2: Serial.println("ATHMO2"); break;
case ATHMO3: Serial.println("ATHMO3"); break;
default: Serial.println(i); break;
}
i++;
if (i==SOUNDCOUNT){i=0;}
delay(50);
}
}
christian
Administrator
 
Beiträge: 10
Registriert: Mo 11. Dez 2017, 07:50

von Anzeige » Fr 12. Jan 2018, 12:41

Anzeige
 

TAGS

Zurück zu Allgemeines

Wer ist online?

0 Mitglieder

cron