Arduino - Volume Control De

  • Uploaded by: ManfredH
  • 0
  • 0
  • February 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Arduino - Volume Control De as PDF for free.

More details

  • Words: 1,018
  • Pages: 12
Loading documents preview...
Arduino – Volume Control Einleitung Die Lautstärke von mehreren Signalquellen soll gemeinsam durch einen gemeinsamen Schweller geregelt werden. Die Lautstärke von MIDI Geräten soll ebenfalls über diesen Schweller gesteuert werden. Die Umsetzung erfolgt mit einem Arduino Mega Microcontroller und digitalen Potentiometern vom Type Microchip MCP42010.

Literatur Beginning Arduino Programming – Technology in Action Arduino Cookbook – O’Reilly

Arduino Mega Quickref siehe http://arduino-info.wikispaces.com/megaquickref

Wichtige Befehle pinMode input input_pullup (Eingang mit Pullup-Widerstand) output digitalWrite(port, value) val = digitalRead(port) delay(milliseconds) shiftout(dataPin, clockPin, bitOrder, value)

Debugausgaben Werden in der seriellen Konsole gemacht. In der Arduino IDE das Fenster mit der seriellen Konsole öffnen. Im setup : Serial. Begin(9600) Serial.println Bem: printf gibt es nicht standardmässing, weil stdio standardmässig nicht eingebunden ist. Es muss speziell eingebunden werden.

Arduino - Volume Control de.docx

1/12

Siehe http://playground.arduino.cc/Main/Printf

Timer FrequencyTimer2 Siehe http://playground.arduino.cc/Code/FrequencyTimer2 Arduino Cookbook S. 245, S548 FrequencyTimer2 Statische Methoden: setPeriod(microseconds) setOnOverfow(callback function) enable() funktioniert aber nicht so richtig … ???

Timer MsTimer2 http://playground.arduino.cc/Main/MsTimer2 MsTimer2 is a small and very easy to use lirary to interface Timer2 with humans. It’s called MsTimer2 because it „hardcodes“ a resolution of 1 millisecond on timer2. MsTimer2::set( milliseconds, callback function) start() stop() So gehts!

Einbinden der Library Siehe https://www.youtube.com/watch?v=R-kWY6eSa64 Arduino IDE Sketch → Import Library → Manage Libraries Filter: FrequencyTimer2 Install

Analog Input – analoge Ports einlesen Arduino Cookbook S. 152 Val = analogRead(port)

Arduino - Volume Control de.docx

//liefert Werte zwischen [0, 1023]

2/12

Debugausgabe analoge Werte Siehe https://www.arduino.cc/en/Serial/Println void loop() { // read the analog input on pin 0: analogValue = analogRead(0); // print it out in many formats: Serial.println(analogValue); // print as an ASCII-encoded decimal Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal Serial.println(analogValue, OCT); // print as an ASCII-encoded octal Serial.println(analogValue, BIN); // print as an ASCII-encoded binary // delay 10 milliseconds before the next reading: delay(10); }

Analog Output - PWM ausgeben Arduino Cookbook S. 217 void setup() { // pins driven by analogWrite do not need to be declared as outputs } analogWrite(port, value) value = 0 → 0 Volt value = 255 → 5 Volt

Map analogRead → analogWrite int brightness = map( analogRead(port),0,1023, 0, 255); // get brightness from sensor The brightness variable will range in value from 0 to 255 as the analog input ranges from 0 to 1,023, causing the LED to increase brightness as the value increases.

Buzzer - Sounder Arduino Cookbook S. 299 geht mit PWM tone(speakerPin, frequence, duration ms) //play the tone

Arduino - Volume Control de.docx

3/12

delay(duration) // wait for the tone to finish  Wichtig!

Serial Peripheral Interface (SPI) Arduino Cookbook S. 389, 391 Siehe https://www.arduino.cc/en/Reference/SPI Siehe auch http://www.eeherald.com/section/design-guide/esmod12.html SPI-Master, SPI-Slave Signal MISO MOSI SCLK /SS

Bedeutung Master Input Slave Output Master Output Slave Input System Clock (clock) Slave Select

Pin Arduino Mega 50 51 52 53

ICSP Stecker auf Board 1 4 3 53

Auf der separaten Buchsenleiste ICSP ist ein zweiter SPI-Bus vorhanden.

Arduino - Volume Control de.docx

4/12

Bem: Auf der separaten Buchsenleiste ICSP ist noch ein ein zweiter SPI-Bus vorhanden, neben dem USB-Bus (ICSP1). Wozu der gut ist, muss ich noch herausfinden…

Arduino - Volume Control de.docx

5/12

Full Duplex

Arduino - Volume Control de.docx

6/12

Daisy Chain

Alle Slaves bilden ein großes Schieberegister. But we have to remember that the daisy-chain will not work with devices which support or require multiple bytes operation.

Arduino - Volume Control de.docx

7/12

Independent Slave Configuration

Arduino Cookbook S. 418 #include <SPI.h> const int slaveSelect = 10;

//pin used to enable the active slave

SPISettings(speedMaximum, MSBFIRST, SPI_MODE0) //speedmaximum = 14000000 SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0)) SPI.begin() pinMode(slaveSelect, OUTPUT) digitalWrite(slaveSelect, LOW); Arduino - Volume Control de.docx

//select slave 8/12

SPI.transfer(value); Transferiert ein Byte, egal welchen Datentypen value hat (z.B. int) Bem: ein 16 Bit Wort transferiert man mit SPI.transfer16(value16), eine beliebige Anzahl an Bits mit SPI.transfer(buffer, size) … digitalWrite(slaveSelect, HIGH);

//deselect slave

SPI.endTransaction();

//beendet eine SPI Kommandosequenz

Bem.: Die SPI-Transaktion ist nützlich, weil sie keine weiteren SPI-Transaktionen zulässt, solange die laufende nicht abgeschlossen ist (z.B. eine aus einer Interrupt-Serviceroutine).

Transfermodes SPI_MODE0, … SPI_MODE3 Meistens passt SPI_MODE0

Digital Potentiometer – Example Siehe https://www.arduino.cc/en/Tutorial/DigitalPotControl

Midi Out – TX – weitere serielle Schnittstelle benutzen Siehe https://www.arduino.cc/en/Tutorial/Midi Wichtig! Ein MIDI Ausgang braucht zwei 220 Ohm Widerstände!!! Siehe http://www.midi.org/techspecs/electrispec.php Siehe http://www.midi.org/techspecs/ca33.pdf

Arduino - Volume Control de.docx

9/12

Hier kann man genauso die Befehle für die serielle Schnittstelle verwenden. // plays a MIDI note. Doesn't check to see that // cmd is greater than 127, or that data values are less than 127: void noteOn(int cmd, int pitch, int velocity) { Serial.write(cmd); Serial.write(pitch); Serial.write(velocity); } Für die MIDI-Schnittstelle benutzen wir eine weitere serielle Schnittstelle (TX1). Die Befehle heißen analog Serial1.xxx Siehe https://www.arduino.cc/en/Tutorial/MultiSerialMega Serial1.begin(31250); // baud // read from port 1, send to port 0: if (Serial1.available()) { int inByte = Serial1.read(); Serial.write(inByte); }

Arduino - Volume Control de.docx

10/12

Digitales Potentiometer MCP42010 Siehe http://www.microchip.com/wwwproducts/Devices.aspx?product=MCP42010 Aus dem Datenblatt S.13 When laying out the circuit for your digital potentiometer, bypass capacitors should be used. These capacitors should be placed as close as possible to the device pin. A bypass capacitor value of 0.1 μF is recommended. Digital and analog traces should be separated as much as possible on the board, with no traces running underneath the device or the bypass capacitor. Extra precautions should be taken to keep traces with high-frequency signals (such as clock lines) as far as possible from analog traces. Use of an analog ground plane is recommended in order to keep the ground potential the same for all devices on the board. Aufgrund dieser Erkenntnis habe ich die Clock-Leitung nachträglich noch auf der Platine nach oben (zu Vss und Gnd gelegt) und noch einen 100nF Kondensator von Vss nach Gnd eingebaut.

Geräusch beim Verändern der Lautstärke Wenn die Lautstärke schnell geändert wird, entsteht ein Geräusch wenn man einfach den eingelesenen Wert vom Poti auf den MCP42010 schickt. Der Grund dafür liegt in der sprunghaften Änderung des Wiederstandswertes im MCP42010. Lösung Die Änderung der Lautstärke immer in Einerschritten durchführen (value + 1 oder value - 1). Dann ist die Lautstärkeänderung geräuschlos.

Arduino - Volume Control de.docx

11/12

Arduino - Volume Control de.docx

12/12

Related Documents

Arduino - Volume Control De
February 2021 0
Arduino
January 2021 6
Arduino
February 2021 1
Makalah Arduino
January 2021 0
Arduino+matlab
January 2021 0
Tutorial Arduino
February 2021 2

More Documents from "Matheus Oliveira"

Arduino - Volume Control De
February 2021 0