Skip to content

Commit

Permalink
Update README; add dualMocoLUFA; redo schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonk committed May 6, 2022
1 parent 042050b commit a2dac98
Show file tree
Hide file tree
Showing 730 changed files with 228,487 additions and 10 deletions.
84 changes: 74 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# arduino-pitch_detector
# Arduino Pitch Detector

[![GitHub Discussions](https://img.shields.io/github/discussions/johanvonk/Arduino_Pitch-Detector)](https://github.com/johanvonk/Arduino_Pitch-Detector/discussions)
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/johanvonk/Arduino_Pitch-Detector)
Expand All @@ -23,7 +23,13 @@ This project uses input from amplified microphone and outputs to a TFT display a

### Schematic

![Schematic](media/pitch-schematic-copy.svg)
Power

![Schematic](hardware/MIDImike-pwr.svg)

Logic

![Schematic](hardware/MIDImike.svg)

To upload the sketch, the USB-MIDI switch needs to be open. The replay button was used during development to replay stored MIDI notes.

Expand All @@ -33,35 +39,93 @@ To upload the sketch, the USB-MIDI switch needs to be open. The replay button wa

| Name | Description | Suggested mfr and part# | Paid |
|------|-------------|-------------------------|-----:|
| MICROPHONE | Electret microphone w/ auto gain control | Adafruit 1713 | [$7.95](https://www.adafruit.com/product/1713)
| ARDUINO | Arduino METRO 328, or Arduino Uno R3 | Adafruit 2488 | [$17.50](https://www.adafruit.com/product/2488)
| ST7735R | ST7735R 1.8" Color TFT display w/ MicroSD breakout | Adafruit 358 | [$19.95](https://www.adafruit.com/product/358)
| PCB1 | Electret microphone w/ auto gain control| Adafruit 1713 | [$7.95](https://www.adafruit.com/product/1713)
| PCB2 | Arduino Uno R3, or Arduino METRO 328 | Adafruit 2488 | [$17.50](https://www.adafruit.com/product/2488)
| PCB3 | ST7735R 1.8" Color TFT display w/ MicroSD breakout | Adafruit 358 | [$19.95](https://www.adafruit.com/product/358)
| SW1 | Switch toggle, SPDT, 5A/120V | E-Switch 100SP1T1B4M2QE | [$2.65](https://www.digikey.com/en/products/detail/e-switch/100SP1T1B4M2QE/378824)
| SW2 | Switch tactile, SPST-NO, 0.05A/24V | TE Connectivity 1825910-3 | [$0.15](https://www.digikey.com/en/products/detail/te-connectivity-alcoswitch-switches/1825910-3/2400476)

### Notes

For the microphone, I use the Adafruit microphone breakout. because it has a 1.25 Volt DC bias and includes an automatic gain control. Other microphones will work for as long as they have a DC biased output, and the output signal is strong enough.
For the microphone, I use the Adafruit microphone breakout, because it has a 1.25 Volt DC bias and includes an automatic gain control. The "max gain" is set to 40 dB by connecting the `GAIN` to `5V`. Other microphones will work for as long as they have a DC biased output, and the output signal is strong enough.

The popular Arduino UNO R3 forms the heart of the system. Note that the REPLAY signal was only used during debugging. This board is now getting hard to find, but you can also use the Arduino METRO 328 or possibly other boards.

If you’re going to reprogramming the Atmega16u2, you need access the companion chip header (ICSP1) as marked in the illustration below.
If you’re going to reprogramming the `Atmega16u2`, you need access the companion chip header (ICSP1) as marked in the illustration below.

![Image](media/pitch-arduino-pins-copy.svg)

## Software

The implementation is in C++ and uses an Arduino, breadboard, microphone and display. It changes the sound wave to an electrical signal; uses autocorrelation to find frequency played; display frequency as note on screen while sending to a MIDI synthesizer.
The implementation changes the sound wave to an electrical signal; uses autocorrelation to find frequency played; display frequency as note on screen while sending to a MIDI synthesizer.[^1]

[^1]: Reprogramming the ATmega16U2 is described in [Sending MIDI Events](https://coertvonk.com/sw/arduino/pitch-detector/sending-midi-events-31581).

### Requirements

| Component | Version tested |
|-----------|----------------|
| Arduino AVR Boards | 1.8.5 (and 1.6.14)
| Arduino IDE | 1.8.19 (and 1.6.12)
| Arduino AVR Boards | 1.8.5 (and 1.6.14)
| Arduino SD library | 1.2.4
| Adafruit BusIO library | 1.11.5
| Adafruit ST7735 and ST7789 library | 1.9.3
| Adafruit GFX Library | 1.11.0

### Build

- Install the libraries.
- If switch `SW1` is closed, open it and power-cycle the device.
- Using the Arduino IDE or Visual Code
- Specify the board, COM port and baud rate.
- Build and upload the sketch .

By default the USB port is used for USB-MIDI, so monitoring the serial port will not show anything useful.

The device is now ready to show the pitch of notes played!

If you want to connect it using USB-MIDI, continue reading.

## USB-MIDI

>Instructions are for Windows, but should equally apply to Linix and MacOS.
The USB on the Arduino talks USB-SERIAL with the host computer. That is how the Serial.print() statements end up on the serial monitor. A small companion chip (ATmega16U2) on the Arduino acts a UART/USB-serial bridge.

We reprogram this companion chip so the Arduino UNO R3 so that, when `SW1` is closed and you power-cycle the device it appears as a MIDI peripheral (HID), and otherwise as a the usual USB-SERIAL port.

This is important that the Arduino can still behave as USB-SERIAL, because this is the usual method of uploading new sketches.

### Match the USB IDs

I patched dualMocoLUFA, so that it matches what is reported by Windows Device Manager's property details.

```
USB\VID_2341&PID_0043&REV_0001
```

If your device shows different details, read [dualMocoLUFA/PATCHES.md](dualMocoLUFA/PATCHES.md) first.

### Install

To install the modified dualMocoLUFA firmware on the ATmega16U2m.

- Install the [Atmel FLexible In-system Programmer](https://www.microchip.com/en-us/development-tool/flip) (FLIP).

- Put the Arduino Uno R3 in DFU mode by briefly connecting the `RESET2*` to `GND` on the atmega16u2 ICSP1 header. These are the leftmost pins, near the USB connector, as shown above.

- In Windows Device Manager, it should show up as “Atmel USB Devices > ATmega16U2“. If you encounter “unknown device“, install the driver from `U:\Program Files (x86)\Atmel\Flip 3.4.7\usb\atmel_usb_dfu.inf`.

- Start Atmel FLIP
- Device » Select » `ATmega16U2`
- Settings » Communication » `USB`
- File » Load HEX File » `dualMocoLUFA/LUFA-100807-patched/Projects/dualMoco.hex`
-

### Connect

If you have a real synthesizer to connect to .. great. Otherwise consider software sequencers to record and play back MIDI events, such as the [free MidiEditor](https://www.midieditor.org/), [Anvil Studio](https://www.anvilstudio.com/), [MuseScore](https://musescore.org/en), [MidiSheetmusic](http://midisheetmusic.com/) or [ScoreCloud](https://scorecloud.com/).

## Design document

Information on the design and implementation can be found at [here](https://coertvonk.com/category/sw/arduino/pitch-detector).
More information on the design and implementation can be found at [here](https://coertvonk.com/category/sw/arduino/pitch-detector).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><ProjectName>BootloaderCDC</ProjectName><Created>13-Jul-2010 14:41:25</Created><LastEdit>13-Jul-2010 14:42:12</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>13-Jul-2010 14:41:25</Created><Version>4</Version><Build>4, 18, 0, 685</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>BootloaderCDC.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Users\Dean\Documents\Electronics\Projects\WORK\LUFAWORK\Bootloaders\CDC\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET></CURRENT_TARGET><CURRENT_PART></CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM></COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>BootloaderCDC.c</SOURCEFILE><SOURCEFILE>Descriptors.c</SOURCEFILE><HEADERFILE>BootloaderCDC.h</HEADERFILE><HEADERFILE>Descriptors.h</HEADERFILE><OTHERFILE>makefile</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>YES</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE>makefile</EXTERNALMAKEFILE><PART>atmega128</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>BootloaderCDC.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR-20100110\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR-20100110\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>C:\Users\Dean\Documents\Electronics\Projects\WORK\LUFAWORK\Bootloaders\CDC\BootloaderCDC.h</Name><Name>C:\Users\Dean\Documents\Electronics\Projects\WORK\LUFAWORK\Bootloaders\CDC\Descriptors.h</Name><Name>C:\Users\Dean\Documents\Electronics\Projects\WORK\LUFAWORK\Bootloaders\CDC\BootloaderCDC.c</Name><Name>C:\Users\Dean\Documents\Electronics\Projects\WORK\LUFAWORK\Bootloaders\CDC\Descriptors.c</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
Loading

0 comments on commit a2dac98

Please sign in to comment.