The Alpha Geek – Geeking Out

Arduino

Arduino

Project #16: Sound – Synthesizer – Mk08

——

#donluc #sound #simplekeyboard #synthesizer #555 #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Synthesizer

——

Synthesizer

——

It is 2015 an microcontroller-based (Arduino), 2 x 555 timer IC music synthesizer. It will be both a hardware and a software synthesizer.

DL2011Mk02

1 x Arduino Pro Mini 328 – 3.3V/8MHz
16 x Tactile Button
4 x 1K Potentiometer
4 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
2 x 555 Timer IC
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 3.3V
Etc…

Arduino Pro Mini 328 – 3.3V/8MHz

SPK – Digital 11
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 9
PO1 – Analog A2
VIN – +3.3V
GND – GND

DL2011Mk02p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - Synthesizer - Mk08
// 11-02
// DL2011Mk02p.ino 16-08
// 1 x Arduino Pro Mini 328 - 3.3V/8MHz
// 16 x Tactile Button
// 4 x 1K Potentiometer
// 4 x Knob
// 1 x Audio Jack 3.5mm
// 1 x SparkFun Audio Jack Breakout
// 1 x Hamburger Mini Speaker
// 2 x 555 Timer IC 
// 1 x SparkFun Cerberus USB Cable
// 1 x SparkFun FTDI Basic Breakout - 3.3V
// Etc...

// Include the Library Code
// Pitches
#include "pitches.h"
// Waveform - Chimes
#include "chimes.h"
using namespace Chimes;
// Sum of ADSR values must not exceed 100%
uint8_t envelope[] = {
  0,  // Attack[%]
  20, // Decay[%]
  0,  // Sustain[%]
  80, // Release[%]
  15  // Sustain Level 1..32
};

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard9 = 9; 
// Button is pressed
int aa = 1;
int bb = 1;
int cc = 1;
int dd = 1;
int ee = 1;
int ff = 1;
int gg = 1;
int hh = 1;

// Frequency
int iCap = A2;
int iFreg = 0;
int iNoteA = 0;
int iNoteB = 0;
int iNoteC = 0;
int iNoteD = 0;
int iNoteE = 0;
int iNoteF = 0;
int iNoteG = 0;
int iNoteAA = 0;

// Software Version Information
String sver = "16-08";

void loop() {

  // Rotary Switch
  //isRotary();
  
  // Frequency
  isPitches();
  
  // Keyboard
  isKeyboard();
  
}

chimes.cpp

/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. 
To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */

#include 
#include "chimes.h"

#define ISR_CYCLE 16 //16s

char strbuf[255];
uint16_t ADSR_default[] = {0, 0, 100, 0, MAX_VOLUME};
uint16_t ADSR_env[5];
uint16_t nSamples; //Number of samples in Array
uint8_t adsrPhase;
uint32_t tPeriod;
uint8_t *samples; //Array with samples
uint8_t *_envelope, _waveform, _duty_cycle;
uint16_t &_sustain_lvl = ADSR_env[4];

enum ADSR_phase
{
	ATTACK,
	DECAY,
	SUSTAIN,
	RELEASE
};

namespace Chimes
{
void init(uint8_t waveform, uint8_t duty_cycle, uint8_t *envelope)
{
	Serial.begin(115200);
	//PWM Signal generation
	DDRB |= (1 << PB3) + (1 << PB0);				  //OC2A, Pin 11
	TCCR2A = (1 << WGM21) + (1 << WGM20);			  //Fast PWM
	TCCR2A |= (0 << COM2A0) + (1 << COM2A1);		  //Set OC2A on compare match, clear OC2A at BOTTOM,(inverting mode).
	TCCR2B = (0 << CS22) + (0 << CS21) + (1 << CS20); //No Prescaling
	samples = (uint8_t *)malloc(0);
	_waveform = waveform;
	_duty_cycle = duty_cycle;
	_envelope = envelope;
}

void play(uint16_t freq, uint16_t duration)
{
	uint8_t waveform = _waveform;
	//Init adsr according to the length of the note
	for (int i = 0; i < 4; i++)
	{
		if (_envelope)
		{
			ADSR_env[i] = (uint32_t)_envelope[i] * duration / 100;
		}
		else
		{
			ADSR_env[i] = (uint32_t)ADSR_default[i] * duration / 100;
		}
		//Serial.println(ADSR_env[i]);
	}
	ADSR_env[4] = _envelope ? _envelope[4] : MAX_VOLUME;
	//Serial.println(ADSR_env[4]);

	if (freq == 0)
	{ //Pause
		tPeriod = ISR_CYCLE * 100;
		waveform = PAUSE;
	}
	else
		tPeriod = 1E6 / freq;

	nSamples = tPeriod / ISR_CYCLE;
	realloc(samples, nSamples);
	uint16_t nDuty = (_duty_cycle * nSamples) / 100;

	switch (waveform)
	{
	case SINE: //Sinewave
		for (int i = 0; i < nSamples; i++)
		{
			samples[i] = 128 + 127 * sin(2 * PI * i / nSamples);
		}
		break;

	case TRI: //Triangle
		for (int16_t i = 0; i < nSamples; i++)
		{
			if (i < nDuty)
			{
				samples[i] = 255 * (double)i / nDuty; //Rise
			}
			else
			{
				samples[i] = 255 * (1 - (double)(i - nDuty) / (nSamples - nDuty)); //Fall
			}
		}
		break;
	case RECT: //Rectangle
		for (int16_t i = 0; i < nSamples; i++)
		{
			i < nDuty ? samples[i] = 255 : samples[i] = 0;
		}
		break;
	case PAUSE: //Rectangle
		memset(samples, 0, nSamples);
	}
	TIMSK2 = (1 << TOIE2);
	/*for(uint16_t i = 0; i < nSamples; i++) {
		sprintf(strbuf, "%d: %d", i, samples[i]);
		Serial.println(strbuf);
	}*/
}

//Returns true, while note is playing
boolean isPlaying()
{
	return (1 << TOIE2) & TIMSK2;
}
} // namespace Chimes

//Called every 16s, when TIMER1 overflows
ISR(TIMER2_OVF_vect)
{
	static uint32_t adsr_timer, adsr_time;
	static uint16_t cnt; //Index counter
	static uint8_t sustain_lvl, vol;

	//Set OCR2A to the next value in sample array, this will change the duty cycle accordingly
	OCR2A = vol * samples[cnt] / MAX_VOLUME;
	if (cnt < nSamples - 1)
	{
		cnt++;
	}
	else
	{
		cnt = 0;
		adsr_timer += tPeriod;
		if (adsr_timer >= 10000)
		{ //every 10 millisecond
			adsr_timer = 0;

			switch (adsrPhase)
			{
			case ATTACK:
				if (ADSR_env[ATTACK])
				{
					vol = MAX_VOLUME * (float)adsr_time / ADSR_env[ATTACK];
					if (vol == MAX_VOLUME)
					{ //Attack phase over
						adsrPhase = DECAY;
						adsr_time = 0;
					}
				}
				else
				{
					adsrPhase = DECAY;
					vol = MAX_VOLUME;
					adsr_time = 0;
				}
				break;

			case DECAY:
				if (ADSR_env[DECAY])
				{
					sustain_lvl = _sustain_lvl;
					vol = MAX_VOLUME - (MAX_VOLUME - _sustain_lvl) * (float)adsr_time / ADSR_env[DECAY];
					if (vol <= sustain_lvl)
					{
						adsr_time = 0;
						adsrPhase = SUSTAIN;
					}
				}
				else
				{
					adsrPhase = SUSTAIN;
					sustain_lvl = MAX_VOLUME;
					adsr_time = 0;
				}
				break;

			case SUSTAIN:
				if (adsr_time > ADSR_env[SUSTAIN])
				{
					adsrPhase = RELEASE;
					adsr_time = 0;
				}

				break;
			case RELEASE:
				if (ADSR_env[RELEASE])
				{
					vol = sustain_lvl * (1 - (float)adsr_time / ADSR_env[RELEASE]);
					if (vol == 0)
					{ //Attack phase over
						adsr_time = 0;
						TIMSK2 = (0 << TOIE2);
						adsrPhase = ATTACK;
					}
				}
				else
				{
					adsrPhase = ATTACK;
					vol = 0;
					adsr_time = 0;
					TIMSK2 = (0 << TOIE2);
				}
				break;
			}
			adsr_time += 10;
		}
	}
}

chimes.h

/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. 
To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */

#ifndef CHIMES_H
#define CHIMES_H
#include "Arduino.h"

enum waveform
{
	SINE, //Sinus
	RECT, //Triangle
	TRI,  //Rectangle
	PAUSE //Internal, do not use
};
#define MAX_VOLUME 32

namespace Chimes
{
void init(uint8_t waveform = SINE, uint8_t duty_cycle = 50, uint8_t *envelope = NULL);
void play(uint16_t freq, uint16_t duration);

//Returns true while note is playing
boolean isPlaying();
} // namespace Chimes

#endif

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the pushbutton pin as an input
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard9, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard2) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    aa = aa + 1;
    // Waveform
    isPlaying();
    play(iNoteA, 500);
    
  }
  else
  {
    
    aa = aa - 1;
    
  }    

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard3) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    bb = bb + 1;
    // Waveform
    isPlaying();
    play(iNoteB, 500);
    
  }
  else
  {
    
    bb = bb - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard4) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    cc = cc + 1;
    // Waveform
    isPlaying();
    play(iNoteC, 500);
    
  }
  else
  {
    
    cc = cc - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard5) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    dd = dd + 1;
    // Waveform
    isPlaying();
    play(iNoteD, 500);
    
  }
  else
  {
    
    dd = dd - 1;
    
  }
  
  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard6) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ee = ee + 1;
    // Waveform
    isPlaying();
    play(iNoteE, 500);
    
  }
  else
  {
    
    ee = ee - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard7) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ff = ff + 1;
    // Waveform
    isPlaying();
    play(iNoteF, 500);
    
  }
  else
  {
    
    ff = ff - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard8) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    gg = gg + 1;
    // Waveform
    isPlaying();
    play(iNoteG, 500);
    
  }
  else
  {
    
    gg = gg - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard9) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    hh = hh + 1;
    // Waveform
    isPlaying();
    play(iNoteAA, 500);
    
  }
  else
  {
    
    hh = hh - 1;
    
  }

  // Waveform
  isPlaying();
  play(0, 50);

}

getPitches.ino

// Pitches
// isPitches
void isPitches(){
  
  // Frequency
  iFreg = analogRead(iCap);
  iFreg = map(iFreg, 0, 1023, 1, 6);

  // Range Frequency Note Low => High
  switch ( iFreg ) {
    case 1:
      // NOTE A1
      iNoteA = NOTE_A1;
      iNoteB = NOTE_B1;
      iNoteC = NOTE_C2;
      iNoteD = NOTE_D2;
      iNoteE = NOTE_E2;
      iNoteF = NOTE_F2;
      iNoteG = NOTE_G2;
      iNoteAA = NOTE_A2;
      break;
    case 2:
      // NOTE A2
      iNoteA = NOTE_A2;
      iNoteB = NOTE_B2;
      iNoteC = NOTE_C3;
      iNoteD = NOTE_D3;
      iNoteE = NOTE_E3;
      iNoteF = NOTE_F3;
      iNoteG = NOTE_G3;
      iNoteAA = NOTE_A3;
      break;
    case 3:
      // NOTE A3
      iNoteA = NOTE_A3;
      iNoteB = NOTE_B3;
      iNoteC = NOTE_C4;
      iNoteD = NOTE_D4;
      iNoteE = NOTE_E4;
      iNoteF = NOTE_F4;
      iNoteG = NOTE_G4;
      iNoteAA = NOTE_A4;
      break;
    case 4:
      // NOTE A4
      iNoteA = NOTE_A4;
      iNoteB = NOTE_B4;
      iNoteC = NOTE_C5;
      iNoteD = NOTE_D5;
      iNoteE = NOTE_E5;
      iNoteF = NOTE_F5;
      iNoteG = NOTE_G5;
      iNoteAA = NOTE_A5;
      break;
    case 5:
      // NOTE A5
      iNoteA = NOTE_A5;
      iNoteB = NOTE_B5;
      iNoteC = NOTE_C6;
      iNoteD = NOTE_D6;
      iNoteE = NOTE_E6;
      iNoteF = NOTE_F6;
      iNoteG = NOTE_G6;
      iNoteAA = NOTE_A6;
      break;
    case 6:
      // NOTE A6
      iNoteA = NOTE_A6;
      iNoteB = NOTE_B6;
      iNoteC = NOTE_C7;
      iNoteD = NOTE_D7;
      iNoteE = NOTE_E7;
      iNoteF = NOTE_F7;
      iNoteG = NOTE_G7;
      iNoteAA = NOTE_A7;
      break;
  }
  
}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Waveform
  init(

    // SINE, TRI and RECT
    SINE,
    // Duty cycle 0..100%, only matters for Triangle and Rectangle 
    50,
    // Envelope
  envelope);
 
}

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc...)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc...)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc...)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc...)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc...)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc...)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc...)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc...)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #16: Sound – Tuning – Mk07

——

#donluc #sound #simplekeyboard #synthesizer #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Tuning

——

Tuning

——

Tuning

——

Tuning

Frequencies for equal-tempered scale. The pitches the frequencies of the twelve notes between note A, and note A one octave up from it. Higher pitched notes have larger frequency steps between them, but each step makes an equal change to difference in pitch (one semitone) that we perceive. The piano keyboard is one of the classic ways of viewing the Chromatic scale. Also, the whole pattern of note names repeats after every seven white notes.

There are two main properties of a regular vibration, the amplitude and the frequency, which affect the way it sounds. Amplitude is the size of the vibration, and this determines how loud the sound is. We have already seen that larger vibrations make a louder sound. It is also the origin of the word amplifier, a device which increases the amplitude of a waveform. Frequency is the speed of the vibration, and this determines the pitch of the sound. It is only useful or meaningful for musical sounds, where there is a strongly regular waveform.

Arduino

This simple keyboard how to use the to generate different pitches depending on which button is pressed. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your board, it is possible to measure the amount of resistance produced by a potentiometer as an analog value. Re-maps a number from one range to another. That is, a value of from Low would get mapped to Low, a value of from High to High. Range Frequency Note Low => Note High. Read the state of the pushbutton value, Low a frequency of High.

DL2011Mk01

1 x Arduino Pro Mini 328 – 5V/16MHz
8 x Tactile Button
1 x 1K Potentiometer
1 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
8 x Wire Solid Core – 22 AWG
5 x Jumper Wires 3in M/M
11 x Jumper Wires 6in M/M
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V

Arduino Pro Mini 328 – 5V/16MHz

SPK – Digital 11
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 9
PO1 – Analog A0
VIN – +5V
GND – GND

DL2011Mk01p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - Tuning - Mk07
// 11-01
// DL2011Mk01p.ino 16-07
// 1 x Arduino Pro Mini 328 - 5V/16MHz
// 8 x Tactile Button
// 1 x 1K Potentiometer
// 1 x Knob
// 1 x Audio Jack 3.5mm
// 1 x SparkFun Audio Jack Breakout
// 1 x Hamburger Mini Speaker
// 8 x Wire Solid Core - 22 AWG
// 5 x Jumper Wires 3in M/M
// 11 x Jumper Wires 6in M/M
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x SparkFun FTDI Basic Breakout - 5V

// Include the Library Code
// Pitches
#include "pitches.h"
// Waveform - Chimes
#include "chimes.h"
using namespace Chimes;
// Sum of ADSR values must not exceed 100%
uint8_t envelope[] = {
  0,  // Attack[%]
  20, // Decay[%]
  0,  // Sustain[%]
  80, // Release[%]
  16  // Sustain Level 1..32
};

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard9 = 9; 
// Button is pressed
int aa = 1;
int bb = 1;
int cc = 1;
int dd = 1;
int ee = 1;
int ff = 1;
int gg = 1;
int hh = 1;

// Frequency
int iCap = A0;
int iFreg = 0;
int iNoteA = 0;
int iNoteB = 0;
int iNoteC = 0;
int iNoteD = 0;
int iNoteE = 0;
int iNoteF = 0;
int iNoteG = 0;
int iNoteAA = 0;

// Software Version Information
String sver = "16-07";

void loop() {

  // Frequency
  isPitches();
  
  // Keyboard
  isKeyboard();
  
}

chimes.cpp

/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. 
To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */

#include 
#include "chimes.h"

#define ISR_CYCLE 16 //16s

char strbuf[255];
uint16_t ADSR_default[] = {0, 0, 100, 0, MAX_VOLUME};
uint16_t ADSR_env[5];
uint16_t nSamples; //Number of samples in Array
uint8_t adsrPhase;
uint32_t tPeriod;
uint8_t *samples; //Array with samples
uint8_t *_envelope, _waveform, _duty_cycle;
uint16_t &_sustain_lvl = ADSR_env[4];

enum ADSR_phase
{
	ATTACK,
	DECAY,
	SUSTAIN,
	RELEASE
};

namespace Chimes
{
void init(uint8_t waveform, uint8_t duty_cycle, uint8_t *envelope)
{
	Serial.begin(115200);
	//PWM Signal generation
	DDRB |= (1 << PB3) + (1 << PB0);				  //OC2A, Pin 11
	TCCR2A = (1 << WGM21) + (1 << WGM20);			  //Fast PWM
	TCCR2A |= (0 << COM2A0) + (1 << COM2A1);		  //Set OC2A on compare match, clear OC2A at BOTTOM,(inverting mode).
	TCCR2B = (0 << CS22) + (0 << CS21) + (1 << CS20); //No Prescaling
	samples = (uint8_t *)malloc(0);
	_waveform = waveform;
	_duty_cycle = duty_cycle;
	_envelope = envelope;
}

void play(uint16_t freq, uint16_t duration)
{
	uint8_t waveform = _waveform;
	//Init adsr according to the length of the note
	for (int i = 0; i < 4; i++)
	{
		if (_envelope)
		{
			ADSR_env[i] = (uint32_t)_envelope[i] * duration / 100;
		}
		else
		{
			ADSR_env[i] = (uint32_t)ADSR_default[i] * duration / 100;
		}
		//Serial.println(ADSR_env[i]);
	}
	ADSR_env[4] = _envelope ? _envelope[4] : MAX_VOLUME;
	//Serial.println(ADSR_env[4]);

	if (freq == 0)
	{ //Pause
		tPeriod = ISR_CYCLE * 100;
		waveform = PAUSE;
	}
	else
		tPeriod = 1E6 / freq;

	nSamples = tPeriod / ISR_CYCLE;
	realloc(samples, nSamples);
	uint16_t nDuty = (_duty_cycle * nSamples) / 100;

	switch (waveform)
	{
	case SINE: //Sinewave
		for (int i = 0; i < nSamples; i++)
		{
			samples[i] = 128 + 127 * sin(2 * PI * i / nSamples);
		}
		break;

	case TRI: //Triangle
		for (int16_t i = 0; i < nSamples; i++)
		{
			if (i < nDuty)
			{
				samples[i] = 255 * (double)i / nDuty; //Rise
			}
			else
			{
				samples[i] = 255 * (1 - (double)(i - nDuty) / (nSamples - nDuty)); //Fall
			}
		}
		break;
	case RECT: //Rectangle
		for (int16_t i = 0; i < nSamples; i++)
		{
			i < nDuty ? samples[i] = 255 : samples[i] = 0;
		}
		break;
	case PAUSE: //Rectangle
		memset(samples, 0, nSamples);
	}
	TIMSK2 = (1 << TOIE2);
	/*for(uint16_t i = 0; i < nSamples; i++) {
		sprintf(strbuf, "%d: %d", i, samples[i]);
		Serial.println(strbuf);
	}*/
}

//Returns true, while note is playing
boolean isPlaying()
{
	return (1 << TOIE2) & TIMSK2;
}
} // namespace Chimes

//Called every 16s, when TIMER1 overflows
ISR(TIMER2_OVF_vect)
{
	static uint32_t adsr_timer, adsr_time;
	static uint16_t cnt; //Index counter
	static uint8_t sustain_lvl, vol;

	//Set OCR2A to the next value in sample array, this will change the duty cycle accordingly
	OCR2A = vol * samples[cnt] / MAX_VOLUME;
	if (cnt < nSamples - 1)
	{
		cnt++;
	}
	else
	{
		cnt = 0;
		adsr_timer += tPeriod;
		if (adsr_timer >= 10000)
		{ //every 10 millisecond
			adsr_timer = 0;

			switch (adsrPhase)
			{
			case ATTACK:
				if (ADSR_env[ATTACK])
				{
					vol = MAX_VOLUME * (float)adsr_time / ADSR_env[ATTACK];
					if (vol == MAX_VOLUME)
					{ //Attack phase over
						adsrPhase = DECAY;
						adsr_time = 0;
					}
				}
				else
				{
					adsrPhase = DECAY;
					vol = MAX_VOLUME;
					adsr_time = 0;
				}
				break;

			case DECAY:
				if (ADSR_env[DECAY])
				{
					sustain_lvl = _sustain_lvl;
					vol = MAX_VOLUME - (MAX_VOLUME - _sustain_lvl) * (float)adsr_time / ADSR_env[DECAY];
					if (vol <= sustain_lvl)
					{
						adsr_time = 0;
						adsrPhase = SUSTAIN;
					}
				}
				else
				{
					adsrPhase = SUSTAIN;
					sustain_lvl = MAX_VOLUME;
					adsr_time = 0;
				}
				break;

			case SUSTAIN:
				if (adsr_time > ADSR_env[SUSTAIN])
				{
					adsrPhase = RELEASE;
					adsr_time = 0;
				}

				break;
			case RELEASE:
				if (ADSR_env[RELEASE])
				{
					vol = sustain_lvl * (1 - (float)adsr_time / ADSR_env[RELEASE]);
					if (vol == 0)
					{ //Attack phase over
						adsr_time = 0;
						TIMSK2 = (0 << TOIE2);
						adsrPhase = ATTACK;
					}
				}
				else
				{
					adsrPhase = ATTACK;
					vol = 0;
					adsr_time = 0;
					TIMSK2 = (0 << TOIE2);
				}
				break;
			}
			adsr_time += 10;
		}
	}
}

chimes.h

/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. 
To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */

#ifndef CHIMES_H
#define CHIMES_H
#include "Arduino.h"

enum waveform
{
	SINE, //Sinus
	RECT, //Triangle
	TRI,  //Rectangle
	PAUSE //Internal, do not use
};
#define MAX_VOLUME 32

namespace Chimes
{
void init(uint8_t waveform = SINE, uint8_t duty_cycle = 50, uint8_t *envelope = NULL);
void play(uint16_t freq, uint16_t duration);

//Returns true while note is playing
boolean isPlaying();
} // namespace Chimes

#endif

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the pushbutton pin as an input
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard9, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard2) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    aa = aa + 1;
    // Waveform
    isPlaying();
    play(iNoteA, 1000);
    
  }
  else
  {
    
    aa = aa - 1;
    
  }    

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard3) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    bb = bb + 1;
    // Waveform
    isPlaying();
    play(iNoteB, 1000);
    
  }
  else
  {
    
    bb = bb - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard4) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    cc = cc + 1;
    // Waveform
    isPlaying();
    play(iNoteC, 1000);
    
  }
  else
  {
    
    cc = cc - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard5) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    dd = dd + 1;
    // Waveform
    isPlaying();
    play(iNoteD, 1000);
    
  }
  else
  {
    
    dd = dd - 1;
    
  }
  
  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard6) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ee = ee + 1;
    // Waveform
    isPlaying();
    play(iNoteE, 1000);
    
  }
  else
  {
    
    ee = ee - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard7) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ff = ff + 1;
    // Waveform
    isPlaying();
    play(iNoteF, 1000);
    
  }
  else
  {
    
    ff = ff - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard8) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    gg = gg + 1;
    // Waveform
    isPlaying();
    play(iNoteG, 1000);
    
  }
  else
  {
    
    gg = gg - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard9) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    hh = hh + 1;
    // Waveform
    isPlaying();
    play(iNoteAA, 1000);
    
  }
  else
  {
    
    hh = hh - 1;
    
  }

  // Waveform
  isPlaying();
  play(0, 50);

}

getPitches.ino

// Pitches
// isPitches
void isPitches(){
  
  // Frequency
  iFreg = analogRead(iCap);
  iFreg = map(iFreg, 0, 1023, 1, 6);

  // Range Frequency Note Low => High
  switch ( iFreg ) {
    case 1:
      // NOTE A1
      iNoteA = NOTE_A1;
      iNoteB = NOTE_B1;
      iNoteC = NOTE_C2;
      iNoteD = NOTE_D2;
      iNoteE = NOTE_E2;
      iNoteF = NOTE_F2;
      iNoteG = NOTE_G2;
      iNoteAA = NOTE_A2;
      break;
    case 2:
      // NOTE A2
      iNoteA = NOTE_A2;
      iNoteB = NOTE_B2;
      iNoteC = NOTE_C3;
      iNoteD = NOTE_D3;
      iNoteE = NOTE_E3;
      iNoteF = NOTE_F3;
      iNoteG = NOTE_G3;
      iNoteAA = NOTE_A3;
      break;
    case 3:
      // NOTE A3
      iNoteA = NOTE_A3;
      iNoteB = NOTE_B3;
      iNoteC = NOTE_C4;
      iNoteD = NOTE_D4;
      iNoteE = NOTE_E4;
      iNoteF = NOTE_F4;
      iNoteG = NOTE_G4;
      iNoteAA = NOTE_A4;
      break;
    case 4:
      // NOTE A4
      iNoteA = NOTE_A4;
      iNoteB = NOTE_B4;
      iNoteC = NOTE_C5;
      iNoteD = NOTE_D5;
      iNoteE = NOTE_E5;
      iNoteF = NOTE_F5;
      iNoteG = NOTE_G5;
      iNoteAA = NOTE_A5;
      break;
    case 5:
      // NOTE A5
      iNoteA = NOTE_A5;
      iNoteB = NOTE_B5;
      iNoteC = NOTE_C6;
      iNoteD = NOTE_D6;
      iNoteE = NOTE_E6;
      iNoteF = NOTE_F6;
      iNoteG = NOTE_G6;
      iNoteAA = NOTE_A6;
      break;
    case 6:
      // NOTE A6
      iNoteA = NOTE_A6;
      iNoteB = NOTE_B6;
      iNoteC = NOTE_C7;
      iNoteD = NOTE_D7;
      iNoteE = NOTE_E7;
      iNoteF = NOTE_F7;
      iNoteG = NOTE_G7;
      iNoteAA = NOTE_A7;
      break;
  }
  
}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Waveform
  init(

    // SINE, TRI and RECT
    SINE,
    // Duty cycle 0..100%, only matters for Triangle and Rectangle 
    50,
    // Envelope
  envelope);
  
}

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc...)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc...)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc...)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc...)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc...)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc...)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc...)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc...)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #16: Sound – Audacity – Mk06

——

#donluc #sound #audacity #synthesizer #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Audacity

——

Audacity

Audacity

Free, open source, cross-platform audio software. Audacity is an easy-to-use, multi-track audio editor and recorder for Windows, macOS, GNU/Linux and other operating systems. Developed by a group of volunteers as open source.

Recording

Audacity can record live audio through a microphone or mixer, or digitize recordings from other media.

Export / Import

Import, edit, and combine sound files. Export your recordings in many different file formats, including multiple files at once.

Sound Quality

Supports 16-bit, 24-bit and 32-bit. Sample rates and formats are converted using high-quality resampling and dithering.

Plugins

Support for LADSPA, LV2, Nyquist, VST and Audio Unit effect plug-ins. Nyquist effects can be easily modified in a text editor – or you can even write your own plug-in.

Editing

Easy editing with Cut, Copy, Paste and Delete. Also unlimited sequential Undo (and Redo) in the session to go back any number of steps.

Effects

Real-time preview of LADSPA, LV2, VST and Audio Unit (macOS) effects. Plug-in Manager handles plug-in installation and addition/removal of effects and generators from the menus.

Accessibility

Tracks and selections can be fully manipulated using the keyboard. Large range of keyboard shortcuts.

Analysis

Spectrogram view mode for visualizing and selecting frequencies. Plot Spectrum window for detailed frequency analysis.

Arduino

The keyboard functions prevent Arduino Uno a processor ATmega328P to send keystrokes to an attached computer through their micro’s native USB port. Keyboard processor ATmega32U4 command the Leonardo, Micro, Due board, Pro Micro, and Fio v3. The approximately 150 most important functions in Audacity can be controlled and triggered with shortcuts, by pressing multiple keys on the computer keyboard. Keyboard Serial listens for a byte coming from the serial port. When received, the board sends a keystroke back to the computer.

DL2010Mk05

1 x Fio v3 – ATmega32U4
1 x 4×4 Matrix Keypad
8 x Jumper Wires 6in M/F
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable

Fio v3 – ATmega32U4

KP2 – Digital 2
KP3 – Digital 3
KP4 – Digital 4
KP5 – Digital 5
KP6 – Digital 6
KP7 – Digital 7
KP8 – Digital 8
KP9 – Digital 9
VIN – +3.3V
GND – GND

DL2010Mk05p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - Audacity - Mk06
// 10-05
// DL2010Mk05p.ino 16-06
// 1 x Fio v3 - ATmega32U4
// 1 x 4x4 Matrix Keypad
// 8 x Jumper Wires 6in M/F
// 1 x Half-Size Breadboard
// 1 x SparkFun Cerberus USB Cable

// Include the Library Code
// 4x4 Matrix Keypad
#include 
#include "Keyboard.h"

// 4x4 Matrix Keypad
// Four rows
const byte ROWS = 4;
// Four columns
const byte COLS = 4;
// Define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
// Connect to the row pinouts of the keypad
byte rowPins[ROWS] = {5, 4, 3, 2};
// Connect to the column pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6};

// Initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

char customKey;

// Software Version Information
String sver = "16-06";

void loop() {

  // 4x4 Matrix Keypad
  isKeypad();

  delay( 50 );
  
}

getKeypad.ino

// 4x4 Matrix Keypad
// Keypad
void isKeypad() {

  // 4x4 Matrix Keypad
  customKey = customKeypad.getKey();

  if ( customKey == '0' ){
    
    // 0 = Go to Selection Start
    delay(10);
    Keyboard.press(KEY_LEFT_CTRL);
    delay(10);
    Keyboard.press('[');
    delay(10);
    Keyboard.releaseAll();
    
  } 

  if ( customKey == '1' ){

    // 1 = Increase gain on focused track 1 dB.
    delay(10);
    Keyboard.press(KEY_LEFT_ALT);
    delay(10);
    Keyboard.press(KEY_RIGHT_SHIFT);
    delay(10);
    Keyboard.press(KEY_UP_ARROW);
    delay(10);
    Keyboard.releaseAll();

  } 

  if ( customKey == '2' ){
    
    // 2 = Zoom In
    delay(10);
    Keyboard.press(KEY_LEFT_CTRL);
    delay(10);
    Keyboard.press('1');
    delay(10);
    Keyboard.releaseAll();
    
  } 

  if ( customKey == '3' ){
    
    // 3 = Play/Stop
    delay(10);
    Keyboard.press(KEY_LEFT_SHIFT);
    delay(10);
    Keyboard.press('A');
    delay(10);
    Keyboard.releaseAll();
    
  } 

  if ( customKey == '4' ){
    
    // 4 = Decrease gain on focused track 1 dB.
    delay(10);
    Keyboard.press(KEY_LEFT_ALT);
    delay(10);
    Keyboard.press(KEY_RIGHT_SHIFT);
    delay(10);
    Keyboard.press(KEY_DOWN_ARROW);
    delay(10);
    Keyboard.releaseAll();
    
  } 

  if ( customKey == '5' ){
    
    // 5 = Zoom Normal
    delay(10);
    Keyboard.press(KEY_LEFT_CTRL);
    delay(10);
    Keyboard.press('2');
    delay(10);
    Keyboard.releaseAll();
    
  } 

  if ( customKey == '6' ){
    
    // 6 =
    
  } 

  if ( customKey == '7' ){
    
    // 7 =
    
  } 

  if ( customKey == '8' ){
    
    // 8 = Zoom Out
    delay(10);
    Keyboard.press(KEY_LEFT_CTRL);
    delay(10);
    Keyboard.press('3');
    delay(10);
    Keyboard.releaseAll();
    
  } 

  if ( customKey == '9' ){
    
    // 9 =
    
  } 

  if ( customKey == 'A' ){
    
    // A = Skip to Start
    delay(10);
    Keyboard.press(KEY_HOME);
    delay(10);
    Keyboard.releaseAll();
     
  } 

  if ( customKey == 'B' ){
    
    // B = Skip to End
    delay(10);
    Keyboard.press(KEY_END);
    delay(10);
    Keyboard.releaseAll();
     
  } 

  if ( customKey == 'C' ){
    
    // C = 
     
  } 
  
  if ( customKey == 'D' ){
    
    // D = 
     
  } 

  if ( customKey == '*' ){
    
     // * =
     
  }

  if ( customKey == '#' ){
    
     // # =
     
  }

}

setup.ino

// Setup
void setup() {

  // Open the serial port
  Serial.begin(9600);
  // Initialize control over the keyboard
  Keyboard.begin();
  
}

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #16: Sound – Waveform – Mk05

——

#donluc #sound #simplekeyboard #synthesizer #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Waveform

——

Waveform

——

Waveform

——

Waveform

In acoustics the waveform of a signal is the shape of its graph as a function of time, independent of its time and magnitude scales and of any displacement in time. In acoustics, it is usually applied to steady periodic sounds—variations of pressure in air or other media. In these cases, the waveform is an attribute that is independent of the frequency, amplitude, or phase shift of the signal. The term can also be used for non-periodic signals, like chirps and pulses. There are certain wave types that are historically used in electronic music, known as classic waveforms: sine, sawtooth, square, and triangle. These are the four waveforms generated by the classic Moog synthesizer oscillators, and are still quite useful in computer music.

Sine Wave

To the human ear, a sound that is made of more than one sine wave will have perceptible harmonics; addition of different sine waves results in a different waveform and thus changes the timbre of the sound. Presence of higher harmonics in addition to the fundamental causes variation in the timbre, which is the reason why the same musical note played on different instruments sounds different.

Synthesizer

A synthesizer is an electronic musical instrument that generates audio signals. Synthesizers generate audio through methods including subtractive synthesis, additive synthesis, and frequency modulation synthesis. These sounds may be shaped and modulated by components such as filters, envelopes, and low-frequency oscillators. Synthesizers are typically played with keyboards.

Simple keyboard in Arduino is a single-oscillator digital synthesizer generates a square wave tone(). But this simply a square wave and so it sounds rather boring. With a simple trick we can generate any waveform with an Arduino, and with this even imitate musical instruments. The adsr object provides a signal in the shape of an ADSR envelope (attack, decay, sustain, release) commonly used in synthesizer design. You specify an attack time in ms, a decay time in ms, a sustain level, and a release time in ms. Arduino waveform sine wave!

DL2010Mk04

1 x Arduino Pro Mini 328 – 5V/16MHz
8 x Tactile Button
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
8 x Wire Solid Core – 22 AWG
1 x Jumper Wires 3in M/M
11 x Jumper Wires 6in M/M
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V

Arduino Pro Mini 328 – 5V/16MHz

SPK – Digital 11
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 9
VIN – +5V
GND – GND

DL2010Mk04p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - Waveform - Mk05
// 10-04
// DL2010Mk04p.ino 16-05
// 1 x Arduino Pro Mini 328 - 5V/16MHz
// 8 x Tactile Button
// 1 x Audio Jack 3.5mm
// 1 x SparkFun Audio Jack Breakout
// 1 x Hamburger Mini Speaker
// 8 x Wire Solid Core - 22 AWG
// 1 x Jumper Wires 3in M/M
// 11 x Jumper Wires 6in M/M
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x SparkFun FTDI Basic Breakout - 5V

// Include the Library Code
// Pitches
#include "pitches.h"
// Waveform - Chimes
#include "chimes.h"
using namespace Chimes;
// Sum of ADSR values must not exceed 100%
uint8_t envelope[] = {
  0,  // Attack[%]
  20, // Decay[%]
  0,  // Sustain[%]
  80, // Release[%]
  16  // Sustain Level 1..32
};

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard9 = 9; 
// Button is pressed
int aa = 1;
int bb = 1;
int cc = 1;
int dd = 1;
int ee = 1;
int ff = 1;
int gg = 1;
int hh = 1;

// Software Version Information
String sver = "16-05";

void loop() {

  // Keyboard
  isKeyboard();
  
}

chimes.cpp

/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. 
To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */

#include 
#include "chimes.h"

#define ISR_CYCLE 16 //16s

char strbuf[255];
uint16_t ADSR_default[] = {0, 0, 100, 0, MAX_VOLUME};
uint16_t ADSR_env[5];
uint16_t nSamples; //Number of samples in Array
uint8_t adsrPhase;
uint32_t tPeriod;
uint8_t *samples; //Array with samples
uint8_t *_envelope, _waveform, _duty_cycle;
uint16_t &_sustain_lvl = ADSR_env[4];

enum ADSR_phase
{
	ATTACK,
	DECAY,
	SUSTAIN,
	RELEASE
};

namespace Chimes
{
void init(uint8_t waveform, uint8_t duty_cycle, uint8_t *envelope)
{
	Serial.begin(115200);
	//PWM Signal generation
	DDRB |= (1 << PB3) + (1 << PB0);				  //OC2A, Pin 11
	TCCR2A = (1 << WGM21) + (1 << WGM20);			  //Fast PWM
	TCCR2A |= (0 << COM2A0) + (1 << COM2A1);		  //Set OC2A on compare match, clear OC2A at BOTTOM,(inverting mode).
	TCCR2B = (0 << CS22) + (0 << CS21) + (1 << CS20); //No Prescaling
	samples = (uint8_t *)malloc(0);
	_waveform = waveform;
	_duty_cycle = duty_cycle;
	_envelope = envelope;
}

void play(uint16_t freq, uint16_t duration)
{
	uint8_t waveform = _waveform;
	//Init adsr according to the length of the note
	for (int i = 0; i < 4; i++)
	{
		if (_envelope)
		{
			ADSR_env[i] = (uint32_t)_envelope[i] * duration / 100;
		}
		else
		{
			ADSR_env[i] = (uint32_t)ADSR_default[i] * duration / 100;
		}
		//Serial.println(ADSR_env[i]);
	}
	ADSR_env[4] = _envelope ? _envelope[4] : MAX_VOLUME;
	//Serial.println(ADSR_env[4]);

	if (freq == 0)
	{ //Pause
		tPeriod = ISR_CYCLE * 100;
		waveform = PAUSE;
	}
	else
		tPeriod = 1E6 / freq;

	nSamples = tPeriod / ISR_CYCLE;
	realloc(samples, nSamples);
	uint16_t nDuty = (_duty_cycle * nSamples) / 100;

	switch (waveform)
	{
	case SINE: //Sinewave
		for (int i = 0; i < nSamples; i++)
		{
			samples[i] = 128 + 127 * sin(2 * PI * i / nSamples);
		}
		break;

	case TRI: //Triangle
		for (int16_t i = 0; i < nSamples; i++)
		{
			if (i < nDuty)
			{
				samples[i] = 255 * (double)i / nDuty; //Rise
			}
			else
			{
				samples[i] = 255 * (1 - (double)(i - nDuty) / (nSamples - nDuty)); //Fall
			}
		}
		break;
	case RECT: //Rectangle
		for (int16_t i = 0; i < nSamples; i++)
		{
			i < nDuty ? samples[i] = 255 : samples[i] = 0;
		}
		break;
	case PAUSE: //Rectangle
		memset(samples, 0, nSamples);
	}
	TIMSK2 = (1 << TOIE2);
	/*for(uint16_t i = 0; i < nSamples; i++) {
		sprintf(strbuf, "%d: %d", i, samples[i]);
		Serial.println(strbuf);
	}*/
}

//Returns true, while note is playing
boolean isPlaying()
{
	return (1 << TOIE2) & TIMSK2;
}
} // namespace Chimes

//Called every 16s, when TIMER1 overflows
ISR(TIMER2_OVF_vect)
{
	static uint32_t adsr_timer, adsr_time;
	static uint16_t cnt; //Index counter
	static uint8_t sustain_lvl, vol;

	//Set OCR2A to the next value in sample array, this will change the duty cycle accordingly
	OCR2A = vol * samples[cnt] / MAX_VOLUME;
	if (cnt < nSamples - 1)
	{
		cnt++;
	}
	else
	{
		cnt = 0;
		adsr_timer += tPeriod;
		if (adsr_timer >= 10000)
		{ //every 10 millisecond
			adsr_timer = 0;

			switch (adsrPhase)
			{
			case ATTACK:
				if (ADSR_env[ATTACK])
				{
					vol = MAX_VOLUME * (float)adsr_time / ADSR_env[ATTACK];
					if (vol == MAX_VOLUME)
					{ //Attack phase over
						adsrPhase = DECAY;
						adsr_time = 0;
					}
				}
				else
				{
					adsrPhase = DECAY;
					vol = MAX_VOLUME;
					adsr_time = 0;
				}
				break;

			case DECAY:
				if (ADSR_env[DECAY])
				{
					sustain_lvl = _sustain_lvl;
					vol = MAX_VOLUME - (MAX_VOLUME - _sustain_lvl) * (float)adsr_time / ADSR_env[DECAY];
					if (vol <= sustain_lvl)
					{
						adsr_time = 0;
						adsrPhase = SUSTAIN;
					}
				}
				else
				{
					adsrPhase = SUSTAIN;
					sustain_lvl = MAX_VOLUME;
					adsr_time = 0;
				}
				break;

			case SUSTAIN:
				if (adsr_time > ADSR_env[SUSTAIN])
				{
					adsrPhase = RELEASE;
					adsr_time = 0;
				}

				break;
			case RELEASE:
				if (ADSR_env[RELEASE])
				{
					vol = sustain_lvl * (1 - (float)adsr_time / ADSR_env[RELEASE]);
					if (vol == 0)
					{ //Attack phase over
						adsr_time = 0;
						TIMSK2 = (0 << TOIE2);
						adsrPhase = ATTACK;
					}
				}
				else
				{
					adsrPhase = ATTACK;
					vol = 0;
					adsr_time = 0;
					TIMSK2 = (0 << TOIE2);
				}
				break;
			}
			adsr_time += 10;
		}
	}
}

chimes.h

/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. 
To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */

#ifndef CHIMES_H
#define CHIMES_H
#include "Arduino.h"

enum waveform
{
	SINE, //Sinus
	RECT, //Triangle
	TRI,  //Rectangle
	PAUSE //Internal, do not use
};
#define MAX_VOLUME 32

namespace Chimes
{
void init(uint8_t waveform = SINE, uint8_t duty_cycle = 50, uint8_t *envelope = NULL);
void play(uint16_t freq, uint16_t duration);

//Returns true while note is playing
boolean isPlaying();
} // namespace Chimes

#endif

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the pushbutton pin as an input
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard9, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard2) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    aa = aa + 1;
    // Waveform
    isPlaying();
    play(NOTE_A4, 1000);
    
  }
  else
  {
    
    aa = aa - 1;
    
  }    

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard3) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    bb = bb + 1;
    // Waveform
    isPlaying();
    play(NOTE_B4, 1000);
    
  }
  else
  {
    
    bb = bb - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard4) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    cc = cc + 1;
    // Waveform
    isPlaying();
    play(NOTE_C5, 1000);
    
  }
  else
  {
    
    cc = cc - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard5) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    dd = dd + 1;
    // Waveform
    isPlaying();
    play(NOTE_D5, 1000);
    
  }
  else
  {
    
    dd = dd - 1;
    
  }
  
  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard6) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ee = ee + 1;
    // Waveform
    isPlaying();
    play(NOTE_E5, 1000);
    
  }
  else
  {
    
    ee = ee - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard7) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ff = ff + 1;
    // Waveform
    isPlaying();
    play(NOTE_F5, 1000);
    
  }
  else
  {
    
    ff = ff - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard8) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    gg = gg + 1;
    // Waveform
    isPlaying();
    play(NOTE_G5, 1000);
    
  }
  else
  {
    
    gg = gg - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard9) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    hh = hh + 1;
    // Waveform
    isPlaying();
    play(NOTE_A5, 1000);
    
  }
  else
  {
    
    hh = hh - 1;
    
  }

  // Waveform
  isPlaying();
  play(0, 50);

}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Waveform
  init(

    // SINE, TRI and RECT
    SINE,
    // Duty cycle 0..100%, only matters for Triangle and Rectangle 
    50,
    // Envelope
  envelope);
  
}

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc...)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc...)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc...)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc...)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc...)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc...)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc...)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc...)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #16: Sound – Simple Keyboard – Mk04

——

#donluc #sound #synthesizer #simplekeyboard #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Simple Keyboard

——

Simple Keyboard

——

Simple Keyboard

——

While frequencies are represented with numbers (Hz), pitch is represented with letters. For example, if you have ever heard an orchestra ‘tune’ at the beginning of a concert, a single player plays an “A” measured at 440Hz. With pitch, we only use the letters A, B, C, D, E, F, and G. These pitches repeat every 8 notes, called an octave. In order to differentiate between which octaves we are referring to when talking about pitch, a number is added after the letter. Simply put in the 19th century and decided that was the case.

One very important aspect of all music theory is that octaves are specifically defined as ‘doubling’ or ‘halving’ a pitch’s frequency. For example, the frequencies 220 Hz, 440 Hz, and 880 Hz are all A’s, but exist in different octaves: A3, A4, and A5 respectively. In Western music theory, we have generally
agreed that within each octave there are 12 equal subdivisions or pitches. So how do we determine where these other notes are ‘tuned’ in relationship to that A440.

Simple Keyboard

This simple keyboard how to use the tone() command to generate different pitches depending on which button is pressed. Connect each button to digital pins 2 => 9, using to ground on each input line. Connect digital pins two wires to the board. The first one black long vertical rows on the side of the breadboard to provide access to ground. The two wire goes from digital pin to one leg of the button. When the button is open (unpressed) there is no connection between the two legs of the button, so the pin is connected to ground and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs. Connect one terminal of your speaker to digital pin 10 through and its other terminal to ground.

The sketch uses an extra file, pitches.h. This file contains all the pitch values for typical notes. This note table on whose work the tone() command was based. You may find it useful for whenever you want to make musical notes. Player plays an NOTE_A4 measured at 440Hz, NOTE_B4 measured at 494Hz, NOTE_C5 measured at 523Hz, NOTE_D5 measured at 587Hz, NOTE_E5 measured at 659Hz, NOTE_F5 measured at 698Hz, NOTE_G5 measured at 784Hz and NOTE_A5 measured at 880Hz.

DL2010Mk03

1 x Arduino Pro Mini 328 – 5V/16MHz
8 x Tactile Button
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
8 x Wire Solid Core – 22 AWG
1 x Jumper Wires 3in M/M
11 x Jumper Wires 6in M/M
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V

Arduino Pro Mini 328 – 5V/16MHz

SPK – Digital 10
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 9
VIN – +5V
GND – GND

DL2010Mk03p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - Simple Keyboard - Mk04
// 10-03
// DL2010Mk03p.ino 16-04
// 1 x Arduino Pro Mini 328 - 5V/16MHz
// 8 x Tactile Button
// 1 x Audio Jack 3.5mm
// 1 x SparkFun Audio Jack Breakout
// 1 x Hamburger Mini Speaker
// 8 x Wire Solid Core - 22 AWG
// 1 x Jumper Wires 3in M/M
// 11 x Jumper Wires 6in M/M
// 2 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x SparkFun FTDI Basic Breakout - 5V

// Include the Library Code
#include "pitches.h"

// Mini Speaker
int SPK = 10;

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard9 = 9; 
// Button is pressed
int aa = 1;
int bb = 1;
int cc = 1;
int dd = 1;
int ee = 1;
int ff = 1;
int gg = 1;
int hh = 1;

// Software Version Information
String sver = "16-04";

void loop() {

  // Keyboard
  isKeyboard();
  
}

getKeyboard.1no

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the pushbutton pin as an input
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard9, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard2) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    aa = aa + 1;
    tone(SPK, NOTE_A4, 20);
    
  }
  else
  {
    
    aa = aa - 1;
    
  }    

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard3) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    bb = bb + 1;
    tone(SPK, NOTE_B4, 20);
    
  }
  else
  {
    
    bb = bb - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard4) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    cc = cc + 1;
    tone(SPK, NOTE_C5, 20);
    
  }
  else
  {
    
    cc = cc - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard5) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    dd = dd + 1;
    tone(SPK, NOTE_D5, 20);
    
  }
  else
  {
    
    dd = dd - 1;
    
  }
  
  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard6) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ee = ee + 1;
    tone(SPK, NOTE_E5, 20);
    
  }
  else
  {
    
    ee = ee - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard7) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    ff = ff + 1;
    tone(SPK, NOTE_F5, 20);
    
  }
  else
  {
    
    ff = ff - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard8) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    gg = gg + 1;
    tone(SPK, NOTE_G5, 20);
    
  }
  else
  {
    
    gg = gg - 1;
    
  }

  // Read the state of the pushbutton value
  if ( digitalRead(iKeyboard9) == LOW ) {

    // Button is pressed - pullup keeps pin high normally
    hh = hh + 1;
    tone(SPK, NOTE_A5, 20);
    
  }
  else
  {
    
    hh = hh - 1;
    
  }

  noTone(SPK);

}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();
  
}

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #16: Sound – Frequency and Pitch – Mk03

——

#donluc #sound #synthesizer #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Frequency and Pitch

——

Frequency and Pitch

——

Frequency and Pitch

——

Frequency and Pitch

Frequency is how often something happens. Since sound is vibrations, we use frequency to describe how often something is vibrating. Frequency is measured in Hertz (Hz), which is simply how often per second. So, something oscillating at 1 Hz is vibrating once every second. A complete vibration is called a cycle, measured at one full peak and trough of a wave. In the early days of electronic music, the terms cycles per second (cps) was used instead of Hz.

The above picture is a sine wave, the purest representation of a single frequency or vibration. The time it takes for the wave to complete one cycle is the wave’s frequency. More vibrations per second produce higher sounding frequencies and fewer vibrations per second produce lower sounding frequencies. Tuning instruments, science experiments, testing audio equipment, testing your hearing what’s the highest frequency you can hear? Humans perceive frequency of sound waves as pitch. Each musical note corresponds to a particular frequency which can be measured in hertz. An infant’s ear is able to perceive frequencies ranging from 20 Hz to 20,000 Hz. The average adult human can hear sounds between 20 Hz and 16,000 Hz.

Tone

The Arduino is a single-oscillator digital synthesizer. Generates a square wave tone() of the specified frequency on a pin. The pin can be connected to a other speaker. Only one tone can be generated at a time. If the tone is playing on the same pin, the call will set its frequency. the Arduino pin on which to generate the tone. The frequency of the tone in hertz. The duration of the tone in milliseconds. By passing voltage through a potentiometer and into an analog input on your board, it is possible to measure the amount of resistance produced by a potentiometer as an frequency.

DL2010Mk02

1 x Arduino Pro Mini 328 – 5V/16MHz
1 x 1K Potentiometer
1 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
5 x Jumper Wires 3in M/M
2 x Jumper Wires 6in M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V

Arduino Pro Mini 328 – 5V/16MHz

SPK – Digital 6
CAP – Analog A0
VIN – +5V
GND – GND

DL2010Mk02p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - Frequency and Pitch - Mk03
// 10-02
// DL2010Mk02p.ino 16-03
// 1 x Arduino Pro Mini 328 - 5V/16MHz
// 1 x 1K Potentiometer
// 1 x Knob
// 1 x Audio Jack 3.5mm
// 1 x SparkFun Audio Jack Breakout
// 1 x Hamburger Mini Speaker
// 5 x Jumper Wires 3in M/M
// 2 x Jumper Wires 6in M/M
// 1 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x SparkFun FTDI Basic Breakout - 5V

// Include the Library Code

// Mini Speaker
int SPK = 6;
// Frequency
int iCap = A0;
int iFreg = 0;

// Software Version Information
String sver = "16-03";

void loop() {

  // Frequency
  iFreg = analogRead(iCap);
  iFreg = map(iFreg, 0, 1023, 31, 4978);
  
  // Mini Speaker  
  tone(SPK, iFreg, 20);
    
  // Delay the actual frequency of updates reads for stability
  delay(1);
  
}

setup.ino

// Setup
void setup() {

  // Setup
  
}

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #16: Sound – Brownian Noise – Mk02

——

#donluc #sound #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Brownian Noise

——

Brownian Noise

——

Brownian Noise

——

Brownian Noise

White noise has equal intensity at equal frequencies. This sounds tinny and harsh to humans. The problem is due to the high frequencies. In order to produce a more pleasant sound, we need to attenuate those high frequencies. This is called a “low pass filter”. Brownian noise is noise with a power density which decreases 6 dB per octave with increasing frequency and, when heard, has a “damped” or “soft” quality compared to white and pink noise.

In science is the kind of signal noise produced by Brownian motion, hence its alternative name of random walk noise. The graphic representation of the sound signal mimics a Brownian pattern. The sound is a low roar resembling a waterfall or heavy rainfall.

Brown Noise Sleep Machine

Brown noise can be produced by integrating white noise. That is, whereas white noise can be produced by randomly choosing each sample independently, Brown noise can be produced by adding a random offset to each sample to obtain the next one. Note that while the first sample is random across the entire range that the sound sample can take on, the remaining offsets from there on are a tenth or thereabouts, leaving room for the signal to bounce around.

This is a pretty common diode. It acts as a flyback, a protective measure to against voltage spikes caused by inductive loads, in this case the speaker. It is basically the same setup, except that an electrolytic decoupling capacitors has been added. I found that 33uF to be suitable. If the output sounds too tinny, which I think is unlikely, then increase the capacitance. As you increase the capacitance, the output volume will go down. So you might try experimenting with a lower capacitance and potentiometer.

DL2010Mk01

1 x Arduino Pro Mini 328 – 5V/16MHz
1 x 1K Potentiometer
1 x Knob
1 x Diode Small Signal – 1N4148
1 x Electrolytic Decoupling Capacitors – 33uF/63V
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
9 x Jumper Wires 3in M/M
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V

Arduino Pro Mini 328 – 5V/16MHz

SPT – Digital 6
VIN – +5V
GND – GND

DL2010Mk01p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - Brownian Noise - Mk02
// 09-02
// DL2010Mk01p.ino 16-02
// 1 x Arduino Pro Mini 328 - 5V/16MHz
// 1 x 1K Potentiometer
// 1 x Knob
// 1 x Diode Small Signal - 1N4148
// 1 x Electrolytic Decoupling Capacitors - 33uF/63V
// 1 x Audio Jack 3.5mm
// 1 x SparkFun Audio Jack Breakout
// 1 x Hamburger Mini Speaker
// 9 x Jumper Wires 3in M/M
// 1 x Full-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x SparkFun FTDI Basic Breakout - 5V

// Include the Library Code

// Mini Speaker
int SPK = 6;
long randNumber;

// Software Version Information
String sver = "16-02";

void loop() {

  // Mini Speaker
  randNumber = random();
  digitalWrite( SPK , randNumber ); 
    
  // Delay the actual frequency of updates
  delayMicroseconds (50);
  
}

setup.ino

// Setup
void setup() {

  // Connect a speaker between ground
  pinMode(SPK, OUTPUT);
  // Random Seed
  randomSeed(analogRead( SPK ));
  
}

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #16: Sound – White Noise – Mk01

——

#donluc #sound #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog

——

Sound - White Noise

——

Sound - White Noise

——

Sound - White Noise

——

White Noise

In signal processing, white noise is a random signal having equal intensity at different frequencies, giving it a constant power spectral density. In other words, the signal has equal power in any band of a given bandwidth when the bandwidth is measured in Hz. The term is used, with this or similar meanings, in many scientific and technical disciplines, including physics, acoustical engineering, telecommunications, and statistical forecasting. White noise refers to a statistical model for signals and signal sources, rather than to any specific signal.

White noise is commonly used in the production of electronic music, usually either directly or as an input for a filter to create other types of noise signal. A simple example of white noise is a nonexistent radio station (static). White noise is also used to obtain the impulse response of an electrical circuit, in particular of amplifiers and other audio equipment. Computing, white noise is used as the basis of some random number generators.

Sounds from all frequencies we can hear. Tends to sound high pitch and tinny. This tends to be the least pleasant noise.

Simple breakout board for the 3.5mm audio jack, TRS are abbreviations for Tip / Ring / Sleeve. A TRS is often though of as stereo, as the addition of the ring gives us two contacts allowing us a left and right audio channel.

DL2009Mk01

1 x Arduino Pro Mini 328 – 5V/16MHz
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
3 x Jumper Wires 3in M/M
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V

Arduino Pro Mini 328 – 5V/16MHz

SPT – Digital 6
SPR – Digital 7
VIN – +5V
GND – GND

DL2009Mk01p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #16: Sound - White Noise - Mk01
// 09-01
// DL2009Mk01p.ino 16-01
// 1 x Arduino Pro Mini 328 - 5V/16MHz
// 1 x Audio Jack 3.5mm
// 1 x SparkFun Audio Jack Breakout
// 1 x Hamburger Mini Speaker
// 3 x Jumper Wires 3in M/M
// 1 x Half-Size Breadboard
// 1 x SparkFun Cerberus USB Cable
// 1 x SparkFun FTDI Basic Breakout - 5V

// Include the Library Code

// Mini Speaker
int Tip = 6;
int Ring = 7;
long randNumber;

// Software Version Information
String sver = "16-01";

void loop() {

  // Mini Speaker
  randNumber = random();
  digitalWrite( Tip , randNumber ); 
  randNumber = random();
  digitalWrite( Ring , randNumber ); 
    
  // Delay the actual frequency of updates
  delayMicroseconds (50);
  
}

setup.ino

// Setup
void setup() {

  // Connect a speaker between ground
  pinMode(Tip, OUTPUT);
  pinMode(Ring, OUTPUT);
  // Random Seed
  randomSeed(analogRead( Tip ));
  randomSeed(analogRead( Ring ));
  
}

Technology Experience

  • Single-Board Microcontrollers (Arduino, Raspberry Pi,Espressif, etc…)
  • Robotics
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/

Don Luc

Project #12: Robotics – Unmanned Vehicles 1h – Mk12

——

Robotics

——

Robotics

——

Robotics

——

Robotics

——

Pololu Stepper Motor Bipolar, 200 Steps/Rev, 2.8V, 1.7 A/Phase

This hybrid bipolar stepping motor has a 1.8° step angle (200 steps/revolution). Each phase draws 1.7 A at 2.8 V, allowing for a holding torque of 3.7 kg-cm. The motor has four color-coded wires terminated with bare leads: black and green connect to one coil; red and blue connect to the other.

DL2003Mk05

1 x SparkFun RedBoard Qwiic
2 x Pololu DRV8834 Low-Voltage Stepper Motor Driver Carrier
2 x Electrolytic Decoupling Capacitors – 100uF/25V
2 x Pololu Stepper Motor Bipolar, 2.8V, 1.7 A/Phase
2 x Pololu Universal Aluminum Mounting Hub for 5mm Shaft, M3 Holes
1 x Adafruit Perma-Proto Half-sized Breadboard PCB
14 x Wire Solid Core – 22 AWG
1 x SparkFun Cerberus USB Cable

SparkFun RedBoard Qwiic

SP1 – Digital 9
DI1 – Digital 8
SP2 – Digital 7
DI2 – Digital 6
VIN – 3.3V
GND – GND

DL2003Mk05Rp.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #12: Robotics - Unmanned Vehicles 1h - Mk12
// 03-05
// DL2003Mk05Rp.ino 12-12
// Receiver
// 1 x SparkFun RedBoard Qwiic
// 2 x Pololu DRV8834 Low-Voltage Stepper Motor Driver Carrier
// 2 x Electrolytic Decoupling Capacitors - 100uF/25V
// 2 x Pololu Stepper Motor Bipolar, 2.8V, 1.7 A/Phase
// 2 x Pololu Universal Aluminum Mounting Hub for 5mm Shaft, M3 Holes
// 1 x Adafruit Perma-Proto Half-sized Breadboard PCB

// Include the library code:
// DRV8834 Stepper Motor Driver
#include <BasicStepperDriver.h>
#include <MultiDriver.h>

// DRV8834 Stepper Motor Driver
// Stepper motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
// Target RPM for X axis stepper motor
#define MOTOR_X_RPM 800
// Target RPM for Y axis stepper motor
#define MOTOR_Y_RPM 800
// Since microstepping is set externally, make sure this matches the selected mode
// If it doesn't, the motor will move at a different RPM than chosen
// 1=full step, 2=half step etc.
#define MICROSTEPS 1
// X Stepper motor
#define DIR_X 8
#define STEP_X 9
// Y Stepper motor
#define DIR_Y 6
#define STEP_Y 7
// BasicStepperDriver
BasicStepperDriver stepperX(MOTOR_STEPS, DIR_X, STEP_X);
BasicStepperDriver stepperY(MOTOR_STEPS, DIR_Y, STEP_Y);
// Pick one of the two controllers below each motor moves independently
MultiDriver controller(stepperX, stepperY);

// Software Version Information
String sver = "12-12";
// Unit ID information
String uid = "";

void loop() {

   controller.rotate(360, 360);
   
}

getStepper.ino

// Stepper
// isStepperSetup
void isStepperSetup() {    
  
  // Set stepper target motors RPM.
  stepperX.begin(MOTOR_X_RPM, MICROSTEPS);
  stepperY.begin(MOTOR_Y_RPM, MICROSTEPS);

}

setup.ino

// Setup
void setup() {

  // DRV8834 Stepper Motor Driver
  isStepperSetup();

}

Technology Experience

  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor

  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL
  • Robotics
  • Arduino
  • Raspberry Pi
  • Espressif

Follow Us

The Alpha Geek

Why “The Alpha Geek”?

Aphasia
https://www.donluc.com/?page_id=2149

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/

Don Luc

Project #12: Robotics – Unmanned Vehicles 1f – Mk10

——

Robotics

——

Robotics

——

Robotics

——

Robotics

——

Robotics

——

Robotics

——

Robotics

——

Robotics

——

Transmitter

DL2002Mk07

1 x Arduino UNO – R3
1 x ProtoScrewShield
1 x Adafruit RGB LCD Shield 16×2 Character Display
1 x XBee S1
1 x SparkFun XBee Explorer Regulated
1 x Slide Pot (Small)
1 x Knob
1 x Acrylic Blue 5.75in x 3.75in x 1/8in
24 x Screw – 4-40
12 x Standoff – Metal 4-40 – 3/8″
7 x Wire Solid Core – 22 AWG
1 x SparkFun XBee Explorer USB
1 x DIGI XCTU Software
1 x SparkFun Cerberus USB Cable

Arduino UNO

TX0 – Digital 1
RX0 – Digital 0
LP1 – Analog A0
VIN – +5V
GND – GND

XBee S1: Transmitter

CH Channel: C
PAN Id: 3333
SH Serial Number: 13A200
SL Serial Number: 40717A1F
CE Coordinator: Coordinator
BD: 9600

DL2002Mk07p.ino

// ***** Don Luc Electronics © *****
// Software Version Information
// Project #12: Robotics - Unmanned Vehicles 1f - Mk10
// 02-07
// DL2002Mk01p.ino 12-10
// Arduino UNO - R3
// ProtoScrewShield
// Adafruit RGB LCD Shield 16×2 Character Display
// EEPROM with Unique ID
// Transmitter
// XBee S1
// Stepper
// Slide Pot (Small)
// Knob

// Include the library code:
// EEPROM library to read and write EEPROM with unique ID for unit
#include <EEPROM.h>
// Adafruit RGB LCD Shield
#include <Adafruit_RGBLCDShield.h>

// Adafruit RGB LCD Shield
Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

// Momentary Button
int yy = 0;
uint8_t momentaryButton = 0;

// Communication
unsigned long dTime = 50;

// Slide Pot (Small)
int iSP1 = A0;                           // Select the input pin for the slide pot
int iValue = 0;                          // Variable to store the value

// The current address in the EEPROM (i.e. which byte we're going to  read to next)
// Version
String sver = "12-10.p";
// Unit ID Information
String uid = "";

void loop() {

  // Clear
  RGBLCDShield.clear();

  // set the cursor to column 0, line 0
  RGBLCDShield.setCursor(0,0);
  RGBLCDShield.print("Robotics");         // Robotics 

  // Momentary Button
  momentaryButton = RGBLCDShield.readButtons();

  switch ( yy ) {
    case 1:
    
      // Forward
      isSwitch1();
      
      break;
    case 2:
    
      // Reverse
      isSwitch2();
      
      break;
    case 3:

      // Right
      isSwitch3();
      
      break;
    case 4:

      // Left
      isSwitch4();
      
      break;
    case 5:

      // Stop
      isSwitch5();
      
      break;
    default:

      // Stop
      yy = 5;
      RGBLCDShield.setBacklight(RED);
      isSwitch5();

   }
   
   if ( momentaryButton ) {
    
    if ( momentaryButton & BUTTON_UP ) {
      
      yy = 1;
      // Forward
      RGBLCDShield.setBacklight(GREEN);
      
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      
      yy = 2;
      // Reverse
      RGBLCDShield.setBacklight(VIOLET);
      
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      
      yy = 3;
      // Right
      RGBLCDShield.setBacklight(TEAL);
      
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {

      yy = 4;
      // Left
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {

      yy = 5;
      // Stop
      RGBLCDShield.setBacklight(RED);
   
    }
    
  }

  // Read the value
  iValue = analogRead( iSP1 );

  // Process Message
  isProcessMessage();

  delay( dTime );
   
}

getEEPROM.ino

// EEPROM
// isUID
void isUID()
{
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 5; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getProcessMessage.ino

// ProcessMessage
// isProcessMessage
void isProcessMessage() {
  
    // Loop through serial buffer
    while ( Serial.available() ) 
   {

      // Print = "<" + yy + "|" + sver + "|" + iValue + "*"
      
      Serial.print( '<'  );
      Serial.print( yy );
      Serial.print( '|' );
      Serial.print( iValue );
      Serial.println( '*' );
         
   }
     
}

getSwitch.ino

// Switch
// Switch 1
void isSwitch1(){

   yy = 1;

   // Stepper 
   // Forward
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Forward");  
   
}
// Switch 2
void isSwitch2(){

   yy = 2;

   // Stepper 
   // Reverse
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Reverse");    
      
}
// Switch 3
void isSwitch3(){

   yy = 3;

   // Stepper 
   // Right
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Right");    
      
}
// Switch 4
void isSwitch4(){

   yy = 4;

   // Stepper 
   // Left
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Left"); 
      
}
// Switch 5
void isSwitch5(){

   yy = 5;
   
   // Stepper 
   // Stop
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Stop");
       
}

setup.ino

// Setup
void setup() {
  
  // Open serial port at 9600 baud
  Serial.begin( 9600 );

  // Pause
  delay(5);

  // EEPROM Unit ID
  isUID();
  
  // Pause
  delay(5);
  
  // Adafruit RGB LCD Shield
  // Set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);
  RGBLCDShield.setBacklight(GREEN);
  
  // Display
  // Set the cursor to column 0, line 0  
  RGBLCDShield.setCursor(0,0);  
  RGBLCDShield.print("Don Luc Electron");         // Don luc Electron
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  RGBLCDShield.print("Robotics");                 // Robotics

  delay(5000);

  // Clear
  RGBLCDShield.clear();

  // Display
  // Set the cursor to column 0, line 0  
  RGBLCDShield.setCursor(0,0);  
  RGBLCDShield.print("Version: ");                // Version
  RGBLCDShield.print( sver );
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  RGBLCDShield.print("UID: ");                    // Unit ID Information
  RGBLCDShield.print( uid );

  delay(5000);

  // Clear
  RGBLCDShield.clear();

}

Follow Us

J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf

Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Web: http://neosteamlabs.com/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Facebook: https://www.facebook.com/neosteam.labs.9/
Instagram: https://www.instagram.com/neosteamlabs/
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Twitter: https://twitter.com/labs_steam
Etsy: https://www.etsy.com/shop/NeoSteamLabs

Don Luc

Categories
Archives