Electronics, Synth, Sound effects, Microcontrollers, , Digital signal processing,AVR, PIC, PIC32,ARM, etc
Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts
Tuesday, 5 May 2015
Wednesday, 29 April 2015
ChipKIT DP32 I2C Bus Speed with a MCP4725 DAC
Both arduino and MPIDE seem to have the I2C bus speed set to 100 kHz by default. So, here it is how to change it to 400kHz.
Inside the MPIDE folder, go to hardware\pic32\libraries\Wire\utility.
Inside file twi.h Find the string #define TWI_FREQ 100000 and change it to: #defineTWI_FREQ 400000.
In my simple test i went from a 20Hz sinewave to a 72Hz just by effecting this change to the bus speed.
Labels:
Arduino,
chipKit,
chipKit DP32,
DAC,
DAC MCP4725,
DP32,
I2C,
Microchip,
Microcontroller,
PIC32,
Wire
Sunday, 26 April 2015
Atmega 328/Uno simple Dub synth
R2R DAC -view picture in the end of article. Usa same principle to build an 8 Bit R2R DAC from D0 to D7
Some intial test sounds out of a Uno mini Dub synth. The file was recorded , unfiltered ( 0 to 5V) and lined out of a guitar amp in clean mode. - Some noise was introduced by the guitar amd as well.
Next step of project is to AC couple signal also with a suitable RC filter, decoupling capacitors and prepare the rest of line out for use with sound gear.
The limitations of the ATMega328 are big compared to the DUE for this kind of project, but good enough to get some interesting sounds, plus it can also double as a dub siren . Sr @ 16kHz-8Bit Dac
You can download /preview it in mp3 here
a 6 bit R2R Dac
Labels:
Arduino,
ATMega328,
Drum Synth,
Dub Drum Synth,
Dub Siren,
Dub Synth,
Jah Shaka,
R2R Dac,
Synare,
Uno
ac coupling of a 0-5 V signal from Atmega328
Example of a signal with dc offset, and after the passive filter
Having a 0 to 5 V signal generated digitally with a R2R 8 bit dac, i needed to remove the offset introduced . This is a simple way and also makes it to "audio friendly" .
Low pass filter and ac coupling circuit block used in one of my projects
Labels:
0-5 V,
AC coupling,
Arduino,
ATMega 328,
audio,
electroics,
RC circuit
Tuesday, 21 April 2015
The Arduino saga for the confused user, Clash Of IDE's and what not's
As confused as most users, i will try break it down gently my perception of it all.
First, you should start by a nicely done history and time line presentation i found, by Matthew Williamson.
Arduino LLC was founded by Massimo Banzi, David Cuartielles, David Mellis, Tom Igoe and Gianluca Martino in 2009.
Considering Arduino idea started around 2005, a lot of these guys had been working togethers since.
The other party is Smart Projects, founded by Gianluca Martino in 2004, which has always been one of the major manufacturers of Arduino Boards.
A rift started ( you can check the full breakdown in the series of articles on Hackaday) and Smart Projects changed their name to Arduino SRL in November of 2014. A new site was started ( arduino.org) and the Clash of IDE's started, confusing a lot of people in the process.
Warnings on some boards started to appear with version 1.6.1 that "Added warning for uncertified boards" ( apparently some USB Vendor ID's from boards manufactured by the "ORG" camp . And this is confusing for the average user.
arduino.cc's version 1.6.3 is the official version, but arduino.org released a few versions with higher numbers to confuse the matter ( 1.7.0 and so on). This version already supports their new Arduino Zero Pro already on sale, while the official team's shop still has it as "Coming soon".
It is sad to see greed, egos and what-not brought to the forefront of public attention, specially regarding a product that is supposed to epitomize the Open Source Community's strength.
Anyone out there surely feels that Arduino is the original idea, perpetuated by the hard work of what is now a massive team. But above all, Arduino is but the massive community that made it what it is today !
All in all... Facepalm !
* Id advise everyone to have a scroll down the hardware index page at arduino.cc and scroll down for some of original boards, etc
First, you should start by a nicely done history and time line presentation i found, by Matthew Williamson.
Arduino LLC was founded by Massimo Banzi, David Cuartielles, David Mellis, Tom Igoe and Gianluca Martino in 2009.
Considering Arduino idea started around 2005, a lot of these guys had been working togethers since.
The other party is Smart Projects, founded by Gianluca Martino in 2004, which has always been one of the major manufacturers of Arduino Boards.
A rift started ( you can check the full breakdown in the series of articles on Hackaday) and Smart Projects changed their name to Arduino SRL in November of 2014. A new site was started ( arduino.org) and the Clash of IDE's started, confusing a lot of people in the process.
Warnings on some boards started to appear with version 1.6.1 that "Added warning for uncertified boards" ( apparently some USB Vendor ID's from boards manufactured by the "ORG" camp . And this is confusing for the average user.
arduino.cc's version 1.6.3 is the official version, but arduino.org released a few versions with higher numbers to confuse the matter ( 1.7.0 and so on). This version already supports their new Arduino Zero Pro already on sale, while the official team's shop still has it as "Coming soon".
It is sad to see greed, egos and what-not brought to the forefront of public attention, specially regarding a product that is supposed to epitomize the Open Source Community's strength.
Anyone out there surely feels that Arduino is the original idea, perpetuated by the hard work of what is now a massive team. But above all, Arduino is but the massive community that made it what it is today !
All in all... Facepalm !
* Id advise everyone to have a scroll down the hardware index page at arduino.cc and scroll down for some of original boards, etc
Labels:
Arduino,
arduino.cc,
arduino.org,
Battle,
IDE,
open source,
Saga,
Smart Projects
Friday, 17 April 2015
ARDUINO NOT THE RIGHT EDUCATIONAL TOOL ?
ARDUINO NOT THE RIGHT EDUCATIONAL TOOL ?
A nice article on a different perspective towards the user-friendly tool
http://www.hackvandedam.nl/blog/?p=762
http://www.hackvandedam.nl/blog/?p=762
Arduino Zero Pro and the Legal Dispute
It is sad that the "thing " that was supposed to be "open Source" causes so much greed and grief.
http://www.i-programmer.info/news/91-hardware/8369-arduino-zero-pro-released-amid-legal-dispute.html
Check the original statement here http://hackaday.com/2015/03/28/arduino-srl-to-distributors-were-the-real-arduino/
You can now find Arduino also at http://arduino.org
http://www.i-programmer.info/news/91-hardware/8369-arduino-zero-pro-released-amid-legal-dispute.html
Check the original statement here http://hackaday.com/2015/03/28/arduino-srl-to-distributors-were-the-real-arduino/
You can now find Arduino also at http://arduino.org
Tuesday, 14 April 2015
ARDUINO IDE 1.6.3 RELEASED
A new version of the Arduino IDE (1.6.3) is available at the download page!
The Arduino IDE 1.6.3 is a bug fix release: after the already released 1.6.2 with new libraries and cores managers.http://blog.arduino.cc/2015/04/02/arduino-ide-1-6-3-released-and-available-for-download/
The Arduino IDE 1.6.3 is a bug fix release: after the already released 1.6.2 with new libraries and cores managers.http://blog.arduino.cc/2015/04/02/arduino-ide-1-6-3-released-and-available-for-download/
Labels:
Arduino,
Arduino DUE,
ATMega328,
AVR,
C code,
IDE,
Microcontroller,
uC
Friday, 5 September 2014
Example Saw waveform generator with R2R DAC ATmega328
/* Example Saw waveform generator with 8 bit R2R DAC pin 0-7
Timer1 Interrupt */ #define WAVE_SAMPLES 256 volatile uint16_t a; uint8_t sample = 0; boolean c; boolean togg; int timer1_counter; void setup() { DDRD = 0xFF; //b11111111 d255 // initialize timer1 cli(); // disable all interrupts TCCR1A = 0; TCCR1B = 0; // Set timer1_counter to the correct value for our interrupt interval timer1_counter = 65443; // preload timer 65536-16MHz/8/21504 Hz TCNT1 = timer1_counter; // preload timer TCCR1B |= (1 << CS11); // clk/8 prescaler TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt sei(); // enable all interrupts } ISR(TIMER1_OVF_vect) // interrupt service routine { TCNT1 = timer1_counter; // preload timer PORTD = sample; togg = !togg; } void loop() { if (c != togg) { a++; if (a >= WAVE_SAMPLES) { a =0; } sample =a; } // c = togg; }
Monday, 4 August 2014
Arduino miniDUBsiren - compact pocket-sized dub siren
While i have to wait for some bits && pots to finish the other prototype, i decided to go back to Arduino Uno and do something quick; Ended up creating the Pocket sized miniDubSiren.
* I have even seen some 3D-printed cases for it here .
LCD Keypad Shield, Arduino Uno and you'd only have to worry about filtering the output. Cant get easier than that .
So, that makes it a shirt-pocket sized Dub Siren.
LFO is linear, for simplicity.
LCD displays top frequency/range and rate of LFO ( both with a minus - and a plus+ button for selection) and when sound is ON (triggered by the SELECT button: toggle action - one click ON , another OFF).
Also made a quick sounds FX generator for it, code to come soon ( even a "slightly slanted" sound wave LCD Char to go with it).
It was nice to work around the limitations of the available buttons and the frequency range in the tone function. Parameters can be changed during play, which creates some nice musical artifacts . A nice little toy.
While at it, developed a nice way of creating menus with this shield( despite not using it in this particular project, where simplicity was needed).
Button arrangement is : Trigger Toggle=Select ; Freq= left/right ; Rate LFO=up/down .
//Sample using LiquidCrystal library
#include < LiquidCrystal.h >
//
byte wavform2[8] = {
B01100,
B10001,
B10001,
B00001,
B00000,
B00000,
B00000,
};
byte wavform[8] = {
B00000,
B00000,
B00000,
B00001,
B10001,
B10010,
B01100,
};
/*******************************************************
miniDubSiren by
Dubworks- Aug 2014
LCD KeyPad Code original by
Mark Bramwell- Jul 2010
********************************************************/// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
uint16_t i = 100; // tone minimum
boolean play = false;
boolean down = false;
uint16_t topFreq = 864;
uint16_t rate = 0;
int outPin = 3; // define number of output pin
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
//
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup()
{
// Serial.begin(9600);
pinMode(outPin, OUTPUT);
lcd.begin(16, 2); // start the library
lcd.createChar(0, wavform );
lcd.createChar(1, wavform2 );
lcdInit();
}
void loop()
{
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
topFreq += 13;
if (topFreq > 4000)
topFreq = 4000;
lcdFnct();
delay(40);
break;
}
case btnLEFT:
{
if (topFreq < 100)
topFreq = 100;
else
topFreq -= 13 ;
lcdFnct();
delay(40);
break;
}
case btnUP:
{
rate += 1 ;
if (rate > 150) {
rate = 150;
}
lcdFnct();
delay(40);
break;
}
case btnDOWN:
{
if (rate < 1)
rate = 0;
else
rate -= 1 ;
delay(40);
lcdFnct();
break;
}
case btnSELECT:
{
play = !play;
if (play == false) {
i = 100;
noTone(3);
delay(50);
}
delay(100);
lcdFnct();
break;
}
case btnNONE:
{
break;
}
}
if (play == true) {
tone(outPin, i);
delay(5); // !!
}
else if (play == false) {
i = 100;
noTone(3);
delay(50);
}
if (down == false) {
i++;
i += rate;
}
else if (down == true) {
i--;
i -= rate;
}
if (i > topFreq) {
down = true;
i = topFreq;
}
else if (i < 180) {
down = false;
i = 180;
}
}
void lcdFnct() {
lcd.clear();
lcd.setCursor(0, 0); //
lcd.print("F= ");
lcd.setCursor(4, 0);
lcd.print(topFreq);
lcd.setCursor(0, 1);
lcd.print("R= ");
lcd.setCursor(4, 1);
lcd.print(rate);
if (play == 1) {
lcd.setCursor(10, 0);
lcd.write(byte(0)); //
lcd.setCursor(11, 0);
lcd.write(byte(1));
lcd.setCursor(10, 1);
lcd.print("ON");
}
}
void lcdInit() {
lcd.setCursor(0, 0);
lcd.print(" = DubWorks = "); //
lcd.setCursor(0, 1);
lcd.print(" mini Dub Siren ");
// scroll 12 positions to the right
// to move it offscreen left:
for (int positionCounter = 0; positionCounter < 12; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(50);
}
// scroll 26 positions to the right
// to move it offscreen right:
for (int positionCounter = 0; positionCounter < 26; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(50);
}
// scroll 14 positions to the left
// to move it back to center:
for (int positionCounter = 0; positionCounter < 14; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(50);
}
// delay at the end of the full loop:
delay(500);
}
3D-Printed case : http://apcmag.com/arduino-project-digital-clock.htm
LCD KEYPAD : http://www.dfrobot.com/wiki/index.phptitle=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)
Labels:
Arduino,
Dub,
DubWorks,
fx,
mini dub siren,
miniDUBsiren,
open source
Tuesday, 12 November 2013
PLBP for chipKit DP32 { Proverbial (4) Led Blink Program }
Will scroll them from right to left, speed varying on the variable resistor on board( trim pot).
/* Proverbial (4) Led Blink Program Scrolls 4 light emitting diodes(LED), by turning on and off connected to 4 different digital pins, using the delay() function and the current millis alike :) . The circuit: * 4 LED's on board - pins D11, D12, D13 and D14 ** Variable resistor/trimpot on A2 *** Version done for the chipKit board DP32 ** **** http://dubworks.blogspot.co.uk/ */ // constants won't change. Used here to // set pin numbers: const int ledPin = 11; // the number of the LED pin const int ledPin1 = 12; const int ledPin2 = 13; const int ledPin3 = 14; int i; // Variables will change: int ledState = LOW; // ledState used to set the LED int ledState1 = LOW; int ledState2 = LOW; int ledState3 = LOW; long previousMillis = 0; // will store last time LED was updated // the follow variables is a long because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. //long interval = 500; // interval at which to blink (milliseconds) void setup() { // set the digital pin as output: pinMode(ledPin, OUTPUT); pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(A2, INPUT); ledState = !ledState; //Toggle the bits to start ledState1 = !ledState1; ledState2 = !ledState2; ledState3 = !ledState3; } void loop() { boolean b; long interval = analogRead(A2); // interval at which to enter function.(milliseconds) interval= interval/3; //So it is not too slow digitalWrite(ledPin, ledState); digitalWrite(ledPin1, ledState1); digitalWrite(ledPin2, ledState2); digitalWrite(ledPin3, ledState3); // // check to see if it's time unsigned long currentMillis = millis(); if(currentMillis - previousMillis > interval) { // save the last time previousMillis = currentMillis; // int var; var=interval-(currentMillis - previousMillis); // conditional depending on increment accumulator if(!b){ switch (i) { case 0 : ledState = !ledState; digitalWrite(ledPin, ledState); delay((var*0.5)); break; case 1 : ledState1 = !ledState1; digitalWrite(ledPin1, ledState1); delay((var)); break; case 2 : ledState2 = !ledState2; digitalWrite(ledPin2, ledState2); delay((var*1.5)); break; case 3 : ledState3 = !ledState3; digitalWrite(ledPin3, ledState3); delay((var*2)); break; default: b=!b; break; } } else{ switch (i) { case 0 : ledState = !ledState; digitalWrite(ledPin, ledState); delay((var*2.5)); break; case 1 : ledState1 = !ledState1; digitalWrite(ledPin1, ledState1); delay((var*3)); break; case 2 : ledState2 = !ledState2; digitalWrite(ledPin2, ledState2); delay((var*3.5)); break; case 3 : ledState3 = !ledState3; digitalWrite(ledPin3, ledState3); delay((var*4)); break; default: b=!b; break; } } i++; // Increment our accumulator i=i%5; // Keep the value within the parameters needed for our switch case // in this case 5, so we can have 4 + 1 // (0, 1, 2 and 3) + 1 for default toggling of boolean variable b. (aesthetic reasons ?!) } }
Monday, 28 October 2013
ADSR Exercises...
The exponential attack curves available will have these different options, in the final version !
I had to try to rethink the ADSR block of my project, as there are some variations that i want to include, and that make it different from other methods more popular often used in synths. Plus, what im building is not your average synth either, so here are some of the results of my tests ! Still need to test it as far as performance goes to be able to decide if ill go with an exponential attack( i am quite confident it can be calculated between interrupts, so as not to weigh too much on the interrupt load, itself !
I tried to make it as readable as possible; There are a lot of short cuts available to make it more efficient and optimize it. Which shall be taken into consideration in the final code . This one was wrote in tutorial style; several of the calculations can be shortened , optimized, for better performance. But then, it wouldn't have been as readable as this, i guess !
So, here it is for now !.
//* Synth Building blocks
//* ATTACK-DECAY-SUSTAIN-RELEASE for Wavetable-based Generator #0.1
//* Check section "Synth building blocks related" @
//* http://dubworks.blogspot.co.uk/p/my-self-documented-tutorials.html
//* Result of my experiences into the ADSR part of my project. Keep in mind that i decided to re-trhink it,
//* as what im working on is not your usual synth, but something else slightly(?!) different.
//* This code was wrote for readability more than anything else ! There are a lot of short cuts available
//* to make it more efficient and optimize it. Which shall be taken into consideration in the final code
#define xinc (1.00/param.attack) // Allows an exponential attack
#define sigl 4095 // Despite being a constant here, it should be replaced by the wavetable equivalent
//
uint32_t phaseinc,output;
//
// Declare the struct for our ADSR
struct ADSR {
uint16_t period; // total of the whole period
uint16_t attack;
uint16_t decay;
uint16_t sustain;
uint16_t rlease;
float x; // increment for period, to accum xinc by addition
};
struct ADSR param; // initialize the structure, so it is in scope !
//
//boolean led = false;
//
void update (){
if(phaseinc <= param.period){
//
if(phaseinc < param.attack){
float y;
y= pow(param.x , 0.50); // Expon. attack-generator. This is where my latest tests been focusing on
output= sigl * y; //Ramp up can be achieved by just multiplying it by param.x as well, though
// it would be a waste of computing power, as there are easier and "cheaper" ways to do it !
// Serial.print ("attack ");
// Serial.println (attack);
// Serial.print ("Output ");
// Serial.println (output);
}
else if(phaseinc >= param.attack && phaseinc <(param.attack + param.decay)){
//
output = sigl-((phaseinc - param.attack)*(512.0/param.decay)); //512= 4096 * 1/8
// Serial.println ("decay");
// Serial.println (param.decay);
// Serial.print ("Output ");
// Serial.println (output);
}
else if(phaseinc >=(param.attack + param.decay) && phaseinc <(param.attack + param.decay + param.sustain)){
//
// Serial.print ("sustain");
// Serial.println (param.sustain);
output = sigl *(7/8.00);
// Serial.print ("Output ");
// Serial.println (output);
}
else if(phaseinc >(param.attack + param.decay + param.sustain) && phaseinc < param.period){
//
// Serial.print ("rlease");
// Serial.println (param.rlease);
output=(param.rlease-(phaseinc-(param.attack+param.decay+param.sustain)))*((sigl*(7/8.00))/param.rlease);
// Serial.print ("Output ");
// Serial.println (output);
}
}
}
//
void ADSR_calculation()
{
// There are more exciting ways to calculate division and remainders.
// We wrap-up with a "modulo-like" operator for
// the last variable sustain- a "greatest-integer function" of sorts .
// This way we can go from decay to release directly. Todo list is to loop inside the sustain
// For now im planning using 3 sec/1 as MAXIMUM of the whole period for ADSR.
uint16_t b = param.period >> 1; // These operations help us achieve a cheap aproximation
param.attack = param.period >> 2;
param.decay = b/3;
param.rlease = param.period >> 2;
param.sustain = param.period -(param.attack + param.rlease + param.decay);
// same as
// param.sustain = param.period %(param.attack + param.rlease + param.decay);
/*if(Serial){
Serial.print ("attack ");
Serial.println (param.attack);
Serial.print ("decay ");
Serial.println (param.decay);
Serial.print ("sustain ");
Serial.println (param.sustain);
Serial.print ("rlease ");
Serial.println (param.rlease);
}*/
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//variable for the period; To be analogous to the analog read/s and should be declared with an initial
//value(21504?!), before the buffering of the initial values , at the time of wavetable generation
param.period=128; //this value should be the sum of all ADSR values, so we can have variable-lenght
// on each of the individual parameters of the ADSR !It is already in the tODO list !
// But for now, ill leave it as it is: weighed proportionally !
//
ADSR_calculation();
}
void loop() {
// if(Serial){
// Serial.print ("phaseinc ");
// Serial.println (phaseinc);
// }
//
update();
//This can be done between interrupts, as there is some calculations involved.
phaseinc++;
//Serial.println(phaseinc);
if( phaseinc >= param.period ){
phaseinc= phaseinc - param.period;
ADSR_calculation();
}
param.x += xinc;
if (param.x >= 1){
param.x = 0;
}
Serial.println (output);
}
Arduino Decimal to Roman numerals converter- The code for Olimex WPC #30
Ok, here is the story :
Friday i saw the "Olimex WPC #30 Problem" just posted and decide to participate...MORE: I was going to try to be the first one to apply a working project, regardless of the "cost".
So i rushed, cheated, took no notice of programming "rules", and VOILA !
Also, as i rarely(?!) see an "Arduino Language" entry ( if you can call it that) , i decided it was what id be applying with ( and because i had nothing else more to code with, at the time :) ).
Added my good mood to the vibes, and this is what came out !
Will only work up to 9999 numbers... If you do a calendar with it, they will probably think it is the end of the world in the year 9999, due to my laziness !!
It was the fastest, laziest way i could find at the time !
* Dont take this code too serious...
**See the results here !https://github.com/OLIMEX/WPC/tree/master/ISSUE-30
Friday i saw the "Olimex WPC #30 Problem" just posted and decide to participate...MORE: I was going to try to be the first one to apply a working project, regardless of the "cost".
So i rushed, cheated, took no notice of programming "rules", and VOILA !
Also, as i rarely(?!) see an "Arduino Language" entry ( if you can call it that) , i decided it was what id be applying with ( and because i had nothing else more to code with, at the time :) ).
Added my good mood to the vibes, and this is what came out !
Will only work up to 9999 numbers... If you do a calendar with it, they will probably think it is the end of the world in the year 9999, due to my laziness !!
It was the fastest, laziest way i could find at the time !
* Dont take this code too serious...
**See the results here !https://github.com/OLIMEX/WPC/tree/master/ISSUE-30
// Enjoy the random names for variables and function at moments.
// and learn how to write down the year that Olimex was founded in Roman numerals
// For completion, i give you the foundation of their fraction system: A twelfth !
// DISCLAIMER : Any similarities with attempt at comedy is pure coincidence !
// CHANGE THIS to test other numbers ( up tp 9999
// | | | | |
// V V V V V
char plaintext[]="1991"; // Why a char[] array? More user friendly with both c and c++
// and because i can !! :)
int tocipher[sizeof(plaintext)];
int ciphered[sizeof(tocipher)];
boolean stringComplete = false; // whether the string is complete
boolean done = false; // no relationship between the name and function ! ;)
void setup() {
// DO NOT put your code here to run once ?!?!
Serial.begin(9600);
Serial.println("Roman Numeral History Lesson with Olimex Pt.1");
}
void loop()
{
while(Serial){
if(stringComplete == true) // How long is a piece of string ?!
{
calculate();
Serial.println("string complete");
fractions();
//
}
if(stringComplete == false){
Serial.println("string NOT complete");
// put your debug code here, to find out where you was going wrong:
uint8_t sizeofarray = sizeof(plaintext);
uint8_t i;
//
for(i=0;i<=sizeofarray;i++)
{
uint16_t retrieved;
retrieved=plaintext[i];
leap(retrieved,i);
Serial.println(retrieved);
if(retrieved==0){
Serial.print(i);
Serial.println(" characters in the string processed.END OF STRING "); // Thats how long a string is :)
Serial.println("null CHARACTER");
stringComplete = true;
// The use of goto's is highly frowned upon...
// ...but can be quite handy as well !
goto bailout;
}
}
bailout: // " Bloody bankers taken all !"
delay(1); // As the tradition says:" Rome and Pavia weren't made in one day!
}
while(done==true){
// Allowing time for Nero to play with fire !
}
}
}
int leap(int in,int il){
// tocipher[il]=in; would have been enough
switch (in) {
case '0':
//
Serial.println("tocipher- 0 ");
tocipher[il]=0;
break;
case '1':
Serial.println("tocipher- 1 ");
tocipher[il]=1;
//
break;
case '2':
Serial.println("tocipher- 2 ");
tocipher[il]=2;
//
break;
case '3':
Serial.println("tocipher- 3 ");
tocipher[il]=3;
//
break;
case '4':
Serial.println("tocipher- 4 ");
tocipher[il]=4;
//
break;
case '5':
Serial.println("tocipher- 5 ");
tocipher[il]=5;
//
break;
case '6':
Serial.println("tocipher- 6 ");
tocipher[il]=6;
//
break;
case '7':
Serial.println("tocipher- 7 ");
tocipher[il]=7;
//
break;
case '8':
Serial.println("tocipher- 8 ");
tocipher[il]=8;
//
break;
case '9':
Serial.println("tocipher- 9 ");
tocipher[il]=9;
//
break;
//
default:
//
break;
//
}
}
void calculate(){
uint16_t sizeofarray = sizeof(tocipher);
int i;
//
for(i=0;i<=sizeofarray;i++)
{
int retrieved;
retrieved=tocipher[i];
bigjump(retrieved,i);
//
}
}
int bigjump(int coming, int il){
switch (il) {
case 0:
int k;
Serial.print("Year Olimex was founded in Roman numerals- ");
for(k=0;k<coming;k++){
Serial.print("M");
}
break;
case 1:
if(coming==9){
Serial.print("CM");
}
if (coming==8){
Serial.print("DCCC");
}
if (coming==7){
Serial.print("DCC");
}
if (coming==6){
Serial.print("DC");
}
if (coming==5){
Serial.print("D");
}
if (coming==4){
Serial.print("CD");
}
if (coming==3){
Serial.print("CCC");
}
if (coming==2){
Serial.print("CC");
}
if (coming==1){
Serial.print("C");
}
break;
case 2:
if(coming==9){
Serial.print("XC");
}
else if (coming==8){
Serial.print("LXXX");
}
else if (coming==7){
Serial.print("LXX");
}
else if (coming==6){
Serial.print("LX");
}
else if (coming==5){
Serial.print("L");
}
else if (coming==4){
Serial.print("XL");
}
else if (coming==3){
Serial.print("XXX");
}
else if (coming==2){
Serial.print("XX");
}
else if (coming==1){
Serial.print("X");
}
break;
case 3:
if(coming==9){
Serial.print("IX");
}
else if (coming==8){
Serial.print("VIII");
}
else if (coming==7){
Serial.print("VII");
}
else if (coming==6){
Serial.print("VI");
}
else if (coming==5){
Serial.print("V");
}
else if (coming==4){
Serial.print("IV");
}
else if (coming==3){
Serial.print("III");
}
else if (coming==2){
Serial.print("II");
}
else if (coming==1){
Serial.print("I");
}
done=true;
break;
case 4:
Serial.println("");
break;
default:
break;
}
}
void fractions(){
// Any similarites with attempt at comedy is pure coincidence !
uint16_t sizeofarray = sizeof(tocipher);
int i;
//
for(i=0;i<=sizeofarray;i++)
{
int retrieved;
int accum;
retrieved=tocipher[i];
int result=0;
switch (i) {
case 0:
//
accum=(retrieved*1000);
Serial.print("result thou ");
Serial.println(accum);
break;
case 1:
accum+=(retrieved*100);
Serial.print("result with hundr");
Serial.println(accum);
//
break;
case 2:
accum+=(retrieved*10);
Serial.print("result with decim ");
Serial.println(accum);
//
break;
case 3:
accum+=retrieved;
Serial.print("total result ");
Serial.println(accum);
//
break;
case 4:
Serial.print("Proverbial 1/12 (twelfth) Roman fracction ");
Serial.print((float)(accum/12));
break;
default:
break;
//
}
}
}
Labels:
Arduino,
C,
C code,
C Programming,
code,
general projects,
makers,
Olimex,
Roman numerals,
Works,
WPC #30
Saturday, 26 October 2013
Problem : Write a decimal to Roman Numerals Converter
Decided to rush and be the first to enter a solution for Olimex's 30th Weekend Programming Contest (WPC #30).
Problem : Write a decimal to Roman Numerals Converter !
I sacrificed a lot on trying to be the first to apply( time will tell if it worked). But did finish a working converter for Arduino (read cumbersome ) !!
Even included the calculation of a twelfth, which was the backbone of their fraction system.
https://github.com/OLIMEX/WPC
http://olimex.wordpress.com/2013/10/25/weekend-programming-challenge-week-30-roman-numbers/
Labels:
Arduino,
C Programming,
converter,
Decimal,
Olimex,
Programming,
Roman numerals,
to,
WPC #30
Wednesday, 23 October 2013
Some exercises with the "Caesar cipher" Pt 2.
Plaintext |a |b |c |d |e |f |g |h |i |j | k | l | m| n| o | p | q | r | s | t | u | v | w | x | y | z |
P-Number |0 |1 |2 | 3 |4 |5 |6 |7 |8 |9 |10|11|12|13|14|15 |16 |17|18|19|20|21|22 |23|24|25|
Ciphertext |d |e | f | g |h |i |j |k |l |m | n | o | p | q | r | s| t | u | v | w | x | y | z | a | b | c |
In the Caesar cipher, the modulus operator was used to achieve a fast way of computing the result.
The use of an array from 0 to 25 is inherent to the discrete implementation methods widely used. Look-up tables also get this particularity many a times !
If it is not obvious why, wait until one of the next posts on the subject. Other examples will surely make obvious why .
Let's remember what was said in a previous post :
// Caesar cipher ==> C = (P+s) Mod (Number_of_Characters)
// Number_of_Characters also known as Keyspace = 26 (0 to 25)
// P = numerical equivalent of character plaintext
// C = Numerical equivalent of cipher text character
// s = number of shifts,adds (n_shift)
// Ke = s = 3 ==> (P+s) mod (Number_of_Characters)
// Kd = -s = -3 ==> (C -s)mod (Number_of_Characters) (reverse operation)
P-Number |0 |1 |2 | 3 |4 |5 |6 |7 |8 |9 |10|11|12|13|14|15 |16 |17|18|19|20|21|22 |23|24|25|
Ciphertext |d |e | f | g |h |i |j |k |l |m | n | o | p | q | r | s| t | u | v | w | x | y | z | a | b | c |
In the Caesar cipher, the modulus operator was used to achieve a fast way of computing the result.
The use of an array from 0 to 25 is inherent to the discrete implementation methods widely used. Look-up tables also get this particularity many a times !
If it is not obvious why, wait until one of the next posts on the subject. Other examples will surely make obvious why .
Let's remember what was said in a previous post :
// Caesar cipher ==> C = (P+s) Mod (Number_of_Characters)
// Number_of_Characters also known as Keyspace = 26 (0 to 25)
// P = numerical equivalent of character plaintext
// C = Numerical equivalent of cipher text character
// s = number of shifts,adds (n_shift)
// Ke = s = 3 ==> (P+s) mod (Number_of_Characters)
// Kd = -s = -3 ==> (C -s)mod (Number_of_Characters) (reverse operation)
From this, we can then adapt this idea into the way the ascii numerical code uses to represent printable characters.
// Keyspace = 96 ( Nchars; )
// P = retrieved
// s = n_shift
// [ from "ascii'" character number 32-decimal; 040-OCT; 20-HEX; 00100000-BIN ==> "SPACE"
// to "ascii'" character number 126 decimal; 176-OCT; 7E-HEX; 01111110-BIN; ==> "~" Equivalence sign - tilde
The way i found was to first subtract an ascii_offset (retrieved -=32;) compute the algorithm ( uint16_t c =(retrieved + n_shift)% Nchars; ) and then re-add the ascii_offset (retrieved +=32;).
The way i found was to first subtract an ascii_offset (retrieved -=32;) compute the algorithm ( uint16_t c =(retrieved + n_shift)% Nchars; ) and then re-add the ascii_offset (retrieved +=32;).
C = (P+s) Mod ( Keyspace )
I should probably note the fact that it should not be confused with the remainder.
Let us see why...
If in C = A modulus B , A=13 and B=5 , then C=3 ;
If C = A remainder B, then it is also C=3.
BUT (and there are always but's) what if we give A=13 and B= -5 ?!
Then, we would get A Modulus B ==> C= -2; In turn, A Remainder B ==> C=3 !!
Oh, yeah !! The art of the Modulus operator in itself ( specially with only the use of a hand calculator), and its relationship with cryptography, is an art in itself , and can easy allow for a series of posts elaborating on it !
As an example, check the table below (created with Gnumeric) .
Code here
https://docs.google.com/document/d/1CbK-v1OaQIhbr0ao5EY8CrGZ71M9-t4cav4bK4JBwo0/edit?usp=sharing
Let us see why...
If in C = A modulus B , A=13 and B=5 , then C=3 ;
If C = A remainder B, then it is also C=3.
BUT (and there are always but's) what if we give A=13 and B= -5 ?!
Then, we would get A Modulus B ==> C= -2; In turn, A Remainder B ==> C=3 !!
Oh, yeah !! The art of the Modulus operator in itself ( specially with only the use of a hand calculator), and its relationship with cryptography, is an art in itself , and can easy allow for a series of posts elaborating on it !
As an example, check the table below (created with Gnumeric) .
https://docs.google.com/document/d/1CbK-v1OaQIhbr0ao5EY8CrGZ71M9-t4cav4bK4JBwo0/edit?usp=sharing
Labels:
Arduino,
ascii,
ascii caesar cipher,
Caesar cipher,
cipher,
code,
cryptography,
electronics,
Math,
RSA
Tuesday, 22 October 2013
Some exercises with the "Caesar cipher"
The Caesar cipher is an example of character or monographic substitution cipher., as it enciphers by substituting a single (mono) character for other single ones.
in the previous related post, the plaintext gives us :
plaintext to encipher- Arduino to cipher this#
Ciphered_array- Dugxlqr#wr#flskhu#wklv&
* you can use the ascii table link for reference.
The Caesar cipher is named after Julius Caesar, who, according to Suetonius, used it with a shift of three to protect messages of military significance.It is unknown how effective the Caesar cipher was at the time, but it is likely to have been reasonably secure, not least because most of Caesar's enemies would have been illiterate and others would have assumed that the messages were written in an unknown foreign language(1)
In cryptography the use of modulus operator is essential. An operation not so easy ( read quick) to do with a calculator I intend to do a whole post on that, as "i love me some maths" !
Not much to say about the Caesar cipher, as most of us tried it as kids at some point. Another widely spread use of it was creating a paper set of double wheels( see below pic).
in the previous related post, the plaintext gives us :
plaintext to encipher- Arduino to cipher this#
Ciphered_array- Dugxlqr#wr#flskhu#wklv&
* you can use the ascii table link for reference.
The Caesar cipher is named after Julius Caesar, who, according to Suetonius, used it with a shift of three to protect messages of military significance.It is unknown how effective the Caesar cipher was at the time, but it is likely to have been reasonably secure, not least because most of Caesar's enemies would have been illiterate and others would have assumed that the messages were written in an unknown foreign language(1)
Of course we can use other shifts; Hal in Arthur C. Clarke's "2001: A Space Odyssey" was chosen as the name for the computer, as it reads 'IBM' with a forward shift of 25 or a back shift of 1 !! Done in a normal 26 letter-only alphabet characters (basic original form)(2).
*There are other funny facts about Hal, actually: the fact that Kubrick is said to have had problems with the initial use of IBM logos, who decided to withdraw them, due to their disapproval of a computer killing people and how that would look like for them, in terms of publicity !
Polemics aside...*There are other funny facts about Hal, actually: the fact that Kubrick is said to have had problems with the initial use of IBM logos, who decided to withdraw them, due to their disapproval of a computer killing people and how that would look like for them, in terms of publicity !
In cryptography the use of modulus operator is essential. An operation not so easy ( read quick) to do with a calculator I intend to do a whole post on that, as "i love me some maths" !
Not much to say about the Caesar cipher, as most of us tried it as kids at some point. Another widely spread use of it was creating a paper set of double wheels( see below pic).
It is as easy as A becomes D( 3 shifts to the right).
Of course this number of shifts can be increased/decreased, and do all sorts of variations in the enciphering key!
So an implementation of the Caesar cipher algorithm would have to be described as :
C=(P+s) Mod (Number_of_Characters)
Number_of_Characters= 26 (also known as keyspace; 26 in the case of low case alphabet only)
P = numerical equivalent of character plaintext
C = Numerical equivalent of ciphertext character
s = number of shifts/adds
Ke== Enciphering Key
Kd==Deciphering Key
*The last two are termed the keys of a cryptosystem.
Kerchoffs' principle enunciates that the security of a cryptosystem must not depend on keeping the cryptographic algorithm secret, but only in keeping the KEYS secret.
Ke= s = 3 ==> (P+s) mod (Number_of_Characters)
Kd = -s = -3 ==> (C -s)mod (Number_of_Characters)
Check Arduino Implementation post here
Labels:
Arduino,
ascii,
ascii caesar cipher,
C code,
C Programming,
Caesar cipher,
cipher,
cryptography,
general projects,
RSA
Subscribe to:
Posts (Atom)


















