Posted on

The simplest Mario speaker song circuit

The other day I stumble upon a simple circuit to create a speaker song. So naturally I try it out and it seems to be quite simple, but it was the sponge bob theme song, so I thought what a boring song. I want a more fun song, and what is more fun and nostalgic than the super Mario theme song, and I manage to find another blog post on Super mario theme song. I analysed the code and found a few improvement that can be made, so naturally I modify the code and factoring he function call. So the Mario speaker song was born.

So here are the circuit connection diagram:

You only need to connect the speaker to GND and another through 1K resistor through pin 3 of the arduino. Once done, you can upload the following code. Continue reading The simplest Mario speaker song circuit

Posted on

Disco Light using LED Strip

My Daughter had a disco night to attend, so what could be better than equipped her with and LED Strip which will flash through the night and making it a blast.

It is also fortunate that the LED strip that I had order through Aliexpress arrived on time along with the Arduino Nano that I had ordered.

Components

Ok, so lets go through the list of components that we need for this:

  • Arduino Uno or nano
  • 5 V addressable LED Strip (WS2812B)
  • Switch
  • Battery pack
  • Cables
  • Recycled belt or back pack strip

Continue reading Disco Light using LED Strip

Posted on

PS3 CFW 4.82

I am trying to use my PS3 today and it seems that my son had accidentally upgrade the firmware to the latest Official Firmware 4.82. Prior to this I am having CFW 4.55 and I haven’t upgrade it cause all the games are still working. so ARRGGGHH!!!

Keep Calm and search google, so I stumble across some fine instruction to flash back the my PS3 CFW 4.82. I use the following link for the instruction

https://gbatemp.net/threads/guide-ps3-4-82-cfw-installation-for-dummies.491117/

The exploit tools patch can be found in the following location.

http://www.psx-place.com/threads/ps3xploit-tools-v2-0-improved-flash-writers-dumpers-even-easier-to-install-cfw-on-4-82-ofw.16139/

To obtain the legit information after being con from few other various sites with firmware that was password protected and trying to get you to sign up for survey or something similar and selling your email address, mobile phone number and the like.

The Custom firmware should be obtained from the following.

REBUG_4.82.1_LITE_c5da00d59e4d1a7aa599e5d0e21415f8 _PS3UPDAT.PUP

I am patiently waiting for the exploit to work its magic, this is the second try and it still not successful.

After gazillion tries, the following steps is the one that is successful.

Use the HDD method instead of USB & follow each of these steps to the letter:

A) Flash NOR
It’s highly recommended to install the 4.82 official firmware twice on your console before using ps3xploit flash writer v2.0.
If your ps3 is already on ofw 4.82 then just install the 4.82 system update PUP again.

Once done, open your ps3 browser, set the homepage to http://ps3xploit.com/writer/index_nor_hdd.html
Restart the browser.
Follow the on screen instructions ie
1. download the flash_482.jpg file
2. initialize exploitation
3. patch flash

When patching is finished, you should get a success message.
To protect your console against any risk of bricking, do NOT turn off or reboot the console just yet, you should validate the Flash memory first.

B) Dump NOR
Now set your homepage to http://ps3xploit.com/dumper/index_nor_hdd.html
Restart your browser.
Follow the on screen instructions ie
1. download the dump.jpg file
2. initialize exploitation
3. dump nor flash

When the dump is done you should get a success message.

C) Validate NOR
Insert a fat32 USB key in ps3.
Go to the Photo colum on XMB, select the dump.jpg file & press the Triangle button. Choose to copy the file to USB device.
On PC, rename the file to dump.hex & use PyPS3checker tool to validate the dump.
You can get this tool from the dev’s github repo:
https://github.com/littlebalup/PyPS3tools
Read PyPS3checker_README.txt for tool requirements & usage syntax. You will need to install python 2.7.15, the installer is available for download on python.org.

In the PyPS3checker validation result screen, if you get either ros0 or ros1 valid with PS3Xploit 4.82 then the patch was successful, you can reboot & install the 4.82 cfw of your choosing. ;)
If the dump isn’t validated, ie you get more than 1 ros warning, do not switch off your console & post here to get further guidance.

Hope it helps.

Posted on

BTCmarket ticker using ESP8266

BTCmarket Ticker with ESP8266

With the recent fall of Bitcoin and other crypto currency and my continue interest in learning more about Arduino, after reading several other instruction of using OLED display, I had combine it all to create a BTCmarket ticker using ESP8266. The reason why I use BTCmarket as the sample is because this is the one that I am currently using, but you can adapt that to any market ticker providing they have API to support data exchange.

Step 1: Gather all the materials needed

The materials used in this are:

  • ESP8266
  • 128×64 0.96″ OLED display

Step 2: Connect the ESP8266 to the OLED display using the following :

  • Connect the SCL of OLED display to D2 of ESP8266
  • Connect the SDA of OLED display to D4 of ESP8266
  • Connect the VCC to 3.3V
  • connect the GND to ground

This is shown in the figure below:

ESP8266 connection diagram
ESP8266 Connection

Step 3: Load library to Arduino

The following instruction assume that you are already familiar with Arduino interface and know where the library is located. For Mac users the Arduino library is located in Documents/Arduino/Libraries.

You will need the ESP8266RestClient library, TimeLib library and the ESP8266_and_ESP32_Oled_Driver_for_SSD1306_display library. Credit goes to their respective author for creating such an awesome library.

Step 4: Load the following code in Arduino interface and upload it to the ESP8266

// BTCMarket Crypto currency ticker
//
// 128x64 OLED pinout:
// GND goes to ground
// Vin goes to 3.3V
// Data to I2C SDA (GPIO 4)
// Clk to I2C SCL (GPIO 2)
#include <TimeLib.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include "RestClient.h"
#include <SSD1306.h>
#include <SSD1306Wire.h>


char ssid[] = "INSERT YOUR SSID HERE"; // your network SSID (name)
char pass[] = "INSERT YOUR NETWORK PASSWORD"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

RestClient restclient = RestClient("api.btcmarkets.net",443,1); 
SSD1306 display(0x3c, 4, 2); //0x3d for the Adafruit 1.3" OLED, 0x3C being the usual address of the OLED


void setup() {
 //Initialize serial and wait for port to open:
 Serial.begin(115200);
 //Setup Rest Client
 WiFi.begin(ssid, pass);

 Wire.pins(4, 2); // Start the OLED with GPIO 4 and 2 on ESP-01
 Wire.begin(4, 2); // 4=sda, 2=scl
 display.init();
 display.flipScreenVertically();
 display.drawString(0, 24, "Connected.");
 display.display();
 delay(1000);
}

void processticker(){
 String response = "";
 //Get the ETH ticker
 int statusCode = restclient.get("/market/ETH/AUD/tick", &response);
 // for some reason sometimes the response is not clean
 String temp = response.substring(response.lastIndexOf("{"), response.lastIndexOf("}")+1);
 //Serial.println("status:" + String(statusCode) + " response:" + temp);
 int rlength = temp.length();
 //Serial.println("Response Length=" + String(rlength));
 char jvar[rlength+1];
 
 temp.toCharArray(jvar, rlength+1);
 //jvar[rlength] = 0;
 StaticJsonBuffer<300> jsonBuffer;
 Serial.println("jvar:" + String(jvar));
 JsonObject& root = jsonBuffer.parseObject(jvar);
if (!root.success()){
 Serial.println(F("Parsing failed!"));
 Serial.println("temp:" + temp);
 } else{
 String Buy = root["bestBid"];
 String Sell = root["bestAsk"];
 String LastTrade = root["lastPrice"];
 time_t tStamp = root["timestamp"];
 tStamp = tStamp + 600 * 60; // GMT + 10
 String TheDate = String(String(day(tStamp)) + "/" + String(month(tStamp)));
 String TheTime = String(String(hour(tStamp)) + ":" + String(minute(tStamp)));
 Serial.println("Buy:"+Buy+"; Sell:"+Sell + "; Last:"+LastTrade );
 display.clear();
 display.drawString(0,0, "ETH/AUD");
 display.drawString(0,13, TheDate +" " + TheTime);
 display.drawString(0,23, "Buy: "+Buy);
 display.drawString(0,33, "Sell: "+Sell);
 display.display();
 }
 
 delay(1000);
}

int timer =0;

void loop() {

if (timer > 5){ // so that we don't call it too frequently we add delay of 5 second
 timer = 0;
 //process ticker
 processticker(); 
 }else{ // handle http client while waiting
 timer++;
 }

delay(1000);
}

You should be able to have the Ethereum ticker now that you can expand to give you an alert they way you want it.

If you like this post, please give a comment or share with your friends. You can also subscribe to my blog for regular updates.

Posted on

IoT Motion Sensor with light

This is the extension of the earlier post IoT Temperature Sensor with ESP8266. The extension is to additional IoT Motion Sensor with light.

Here are the concept picture.

We are going to connect the PIR sensor (motion sensor) to the other free port of the ESP8266. The PIR sensor consist of 3 legs, shown in the following picture:

As you can see, there are tiny marking of +,0,- on the PCB next to the legs. So connect the “+” to 3.3V, “-” to the ground and the middle pin “0” to pin D6 of ESP8266.

To detect the motion we added the following code to our Arduino program:

void handlePIR(){
  DebugLn("handlePIR");
  motion = digitalRead(PIRpin) == HIGH;
  if (motion){
    digitalWrite(LED_BUILTIN, LOW);
    if (locklow){
      // make sure we wait for a transition to LOW before any further output
      locklow = false;
      Serial.print("motion detected at ");
      Serial.print(millis()/1000);
      Serial.println(" sec");
      delay(50);
    }
    takeLowTime = true;
 } else {
   digitalWrite(LED_BUILTIN, HIGH);
   if (takeLowTime){
     lowIn = millis(); // save the time of the transition from high to LOW
     takeLowTime = false; // make sure this is only done at the start of LOW phase
   }
   // if the sensor is low for more than the given pause, assume no more motion is going to happen
   if (!locklow && millis() - lowIn > pause){
   // make sure this block is executed again after new motion sequence had been detected
     locklow = true;
     Serial.print("motion ended at ");
     Serial.print((millis() - pause)/1000);
     Serial.print(" sec");
     delay(50);
   }
 }
 // post to webserver
 data = "pir_sensor=" + String(motion);
 postData(data);
}

The code above will light up the internal LED (Internal LED active LOW) when there is a motion being detected by the sensor.

In the next step we will connect the LED light to the circuit to allow us to control the light from the Internet.

Posted on

Light Activated MP3 player (Part 2/2)

This is the continuation of the Light Activated Mp3 player Part 1.

Once we had tested that our MP3 is fully functional, it is now the time to add the Light sensor. The Light sensor LDR (Light Dependend Resistor) is a passive component that is reactive to light, when the light shine through the LDR, their resistance value decreases. So in order to use this we had to connect the LDR with another Resistor to build a voltage divider. This will provide the feed into the Arduino input.

The updated circuit can be found below:

Arduino Connection

As shown in the circuit above the connection from the voltage divider of LDR and resistor 10K is connected to Arduino input A0. Assuming that you had a working code from Part 1. The following snippet of code allows you to detect the light.

const int LDRpin = A0; // LDR connected to pin A0
 ldrStatus = analogRead(LDRpin);
 //Serial.println(ldrStatus);
 if (ldrStatus >=300){
   digitalWrite(LED_BUILTIN, LOW);
   Serial.print("LED Light");
   mp3.start();
   onStatus = true;
 }

The above code will play the mp3 player when the light is shining on the LDR. The threshold of the brightness in the code is 300, this can be adjusted if you have less light. If you have less light, that means you will need to lower the threshold, a bit of trial and error will give the best result.

And finally instead of using the internal Arduino light, I had added another LED connected to PIN 13 or Arduino. This is shown in the following diagram

Light activated MP3 player

The full source code can be found below:

// this example will play a Track 001 in folder 006
// when light is on the LDR
// it expects the sd card to contain some mp3 files
// LDR is connected with Resistor 10K in series
// Free LDR leg is connected to 5V
// other end of R10K is connected to GND
// joined LDR leg and R10k is connected to pin A0
// LED is connected to pin D13
#include 
#include 
#define DEBUG 0
// implement a notification class,
// its member methods will get called
//
class Mp3Notify
{
public:
 static void OnError(uint16_t errorCode)
 {
 // see DfMp3_Error for code meaning
 Serial.println();
 Serial.print("Com Error ");
 Serial.println(errorCode);
 }
 static void OnPlayFinished(uint16_t track)
 {
 Serial.print("Play finished for #");
 Serial.println(track);
 }
 static void OnCardOnline(uint16_t code)
 {
 Serial.println("Card online ");
 }
 static void OnCardInserted(uint16_t code)
 {
 Serial.println("Card inserted ");
 }
 static void OnCardRemoved(uint16_t code)
 {
 Serial.println("Card removed ");
 }
};
// instance a DFMiniMp3 object,
// defined with the above notification class and the hardware serial class
//
//DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial1);
// Some arduino boards only have one hardware serial port,
//so a software serial port is needed instead.
// comment out the above definition and uncomment these lines
SoftwareSerial secondarySerial(10, 11); // RX, TX
DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(secondarySerial);
const int LDRpin = A0; // LDR connected to pin A0
const int LEDpin = 13; // LED pin D13
int Song=1; //sd:/06/001.mp3
int ldrStatus;
boolean onStatus = true;
boolean takeLowTime;
//the timer to reset song
long unsigned int timeoutTimer = 0, resetCount = 0;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 2000;
void setup()
{

 Serial.begin(115200);
 if (DEBUG) Serial.println("initializing...");
 pinMode(LDRpin, INPUT); // setup LDR
 pinMode(LEDpin, OUTPUT);
mp3.begin();
 mp3.reset();

 // show some properties and set the volume
 uint16_t volume = mp3.getVolume();
 Serial.print("volume ");
 Serial.println(volume);
 mp3.setVolume(20);

 uint16_t count = mp3.getTotalTrackCount();
 Serial.print("files ");
 Serial.println(count);
uint16_t mode = mp3.getPlaybackMode();
 Serial.print("playback mode ");
 Serial.println(mode);

 if (DEBUG) Serial.println("starting...");
 mp3.playFolderTrack(6, Song);
}
void loop()
{
 ldrStatus = analogRead(LDRpin);
 if (ldrStatus >=300){
  digitalWrite(LEDpin, HIGH);
  mp3.start();
  onStatus = true;
 }
 } else {
 digitalWrite(LEDpin, LOW);
 mp3.pause();
 }
 // calling mp3.loop() periodically allows for notifications
 // to be handled without interrupts
 mp3.loop();
}

I hope you had enjoyed the process of building the Light Activated Mp3 player, and hopefully you are well rewarded by giving this gift. Enjoy the final video of the gift that I had made. If you like this please leave me a comment.

https://www.youtube.com/watch?v=UQk4YPjXWLA

Posted on

Light Activated MP3 player (Part 1/2)

Giftbox
Light Activated MP3 Player

Light activated MP3 player was incepted when I wanted to add something special to the present that I gave to my Mrs. So while I was learning about Arduino and have a play with the DFPlayer Mini, which is essentially an MP3 player.

Step 1. Prepare the MP3 Player

First thing to do is to connect the DF Player mini to Arduino using the following circuit.

DFplayerTest

The SD card will need to contain an MP3 file, let’s say the file is 001.mp3, this is located in the 006 folder of the SD card, i.e.: sd:\\006\001.mp3.

Once you connect the diagram above you can use the following code to test to ensure that the DF Player is playing the song you had saved. If you came from Instructables, step 4. you would want the following code to test your DF player.

// this example will play a random track from all on the sd card
// it expects the sd card to contain some mp3 files
#include <SoftwareSerial.h>
#include <DFMiniMp3.h>
// implement a notification class,
// its member methods will get called 
//
class Mp3Notify
{
public:
  static void OnError(uint16_t errorCode)
  {
    // see DfMp3_Error for code meaning
    Serial.println();
    Serial.print("Com Error ");
    Serial.println(errorCode);
  }
  static void OnPlayFinished(uint16_t track)
  {
    Serial.print("Play finished for #");
    Serial.println(track);  
  }
  static void OnCardOnline(uint16_t code)
  {
    Serial.println("Card online ");
  }
  static void OnCardInserted(uint16_t code)
  {
    Serial.println("Card inserted ");
  }
  static void OnCardRemoved(uint16_t code)
  {
    Serial.println("Card removed ");
  }
};
// instance a DFMiniMp3 object, 
// defined with the above notification class and the hardware serial class
//
//DFMiniMp3<hardwareserial, mp3notify> mp3(Serial1);
// Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
// comment out the above definition and uncomment these lines
SoftwareSerial secondarySerial(10, 11); // RX, TX
DFMiniMp3<SoftwareSerial, mp3notify> mp3(secondarySerial);
int Song=1;   // 001.mp3
void setup() {
  Serial.begin(115200);
  Serial.println("initializing...");
  mp3.begin();
  mp3.reset(); 
  
  // show some properties and set the volume
  uint16_t volume = mp3.getVolume();
  Serial.print("volume ");
  Serial.println(volume);
  mp3.setVolume(20);
  
  uint16_t count = mp3.getTotalTrackCount();
  Serial.print("files ");
  Serial.println(count);
  uint16_t mode = mp3.getPlaybackMode();
  Serial.print("playback mode ");
  Serial.println(mode);
  
  Serial.println("starting...");
  
  //mp3.playRandomTrackFromAll(); // random of all folders on sd
  mp3.playFolderTrack(6, Song); // play song on sd:\\006\001.mp3
  delay(5000);
}

void loop() 
{
  // calling mp3.loop() periodically allows for notifications 
  // to be handled without interrupts
  mp3.loop();
}

If you are having trouble loading the “DFMiniMp3” library you can download it from the Instructables step 6, the library called “DFPlayer_Mini_MP3”.

To take it to the next level I added the LDR, which is essentially a resistor which are photosensitive. The resistance changes when there is a light shine through it, combination of the 2 makes up the Light activated MP3 Player. We will go through this in the next part.

 

Posted on

Password Protect PDF document using windows Powershell script

Password protect PDF document can be done using Windows Powershell script. I stumble across a powerful script which allow to password protect PDF document using the script. The requirement that I have is to password protect a list of batch PDF document with a specified password that are different between each document and then sending each password protected PDF document to different individual emails.

So after researching for a while I found the script that does the job, but then I come across another hurdle, how do I get the list of password and the list of pdf, so my solution is to put the list of pdf files along with the password in an excel document, and let the script open the excel find the first pdf document, then read the designated password next to it, and run the script to password protect the file and save the password protected file in a different location.

So hunting around for the powershell script to read excel proven to be fruitful, so I combine both of them into one script. Here are the step by step on what I had done and how to modify this to suit your need. This proven to speed up the manual work by a lot. Not to imagine the time and cost savings that comes along with it.

Step 1. Create the list with location of PDF document and the password that you want to protect the document with.

In picture below, we have the source of document in column B, and the target encrypted PDF file name will be located in the location specified in column C. The password for each document will be based on the information in column D. Save this Excel file in C:\temp\ location and lets call the file Book2.xlsx for this exercise.

Step 2. Open your favourite text editor and paste in the following code, you can also use the “Windows PowerShell ISE“:

[System.Reflection.Assembly]::LoadFrom("itextsharp.dll")

function PSUsing {
 param (
 [System.IDisposable] $inputObject = $(throw "The parameter -inputObject is required."),
 [ScriptBlock] $scriptBlock = $(throw "The parameter -scriptBlock is required.")
 )
 
 Try {
 &$scriptBlock
 }
 Finally {
 if ($inputObject.psbase -eq $null) {
 $inputObject.Dispose()
 } else {
 $inputObject.psbase.Dispose()
 }
 }
}

$xlCellTypeLastCell = 11 
$startRow,$col=2,1

$excel=new-object -com excel.application
$wb=$excel.workbooks.open("c:\temp\Book2.xlsx")

for ($i=1; $i -le $wb.sheets.count; $i++)
 {
 $j=0;
 $sh=$wb.Sheets.Item($i)
 $endRow=$sh.UsedRange.SpecialCells($xlCellTypeLastCell).Row
 $rangeAddress=$sh.Cells.Item($startRow+1,$col).Address() + ":" +$sh.Cells.Item($endRow+1,$col).Address()
 $sh.Range($rangeAddress).Value2 | foreach {
 $contract=$sh.Cells.Item($startRow + $j,$col).Value2
 $filesource = $sh.Cells.Item($startRow + $j,$col+1).Value2
 $filedest = $sh.Cells.Item($startRow + $j,$col+2).Value2
 $dob=$sh.Cells.Item($startRow + $j,$col+3).Value2
 
 New-Object PSObject -Property @{Contract=$contract;Dob=$dob}
 
 $file = New-Object System.IO.FileInfo $filesource
 $fileWithPassword = New-Object System.IO.FileInfo $filedest
 $password = $dob
 PSUsing ( $fileStreamIn = $file.OpenRead() ) { 
 PSUsing ( $fileStreamOut = New-Object System.IO.FileStream($fileWithPassword.FullName,[System.IO.FileMode]::Create,[System.IO.FileAccess]::Write,[System.IO.FileShare]::None) ) { 
 PSUsing ( $reader = New-Object iTextSharp.text.pdf.PdfReader $fileStreamIn ) {
 [iTextSharp.text.pdf.PdfEncryptor]::Encrypt($reader, $fileStreamOut, $true, $password, $password, [iTextSharp.text.pdf.PdfWriter]::ALLOW_PRINTING)
 }
 }
 }
 
 $j++
 }
}
$excel.Workbooks.Close()

 

Step 3. Make sure you have the itextsharp.dll library located in the same location as the PowerShell Script.

In this example it should be located in C:\Temp\. You should have the folder structure that looks similar to the one below.

Step 4. Put the source PDF files as specified in the step 1. Execute the Powershell Script by clicking on the execute button if you are using Windows PowerShell ISE.

Step 5. If everything went well, you should be able to see the execution message as per the picture below.

Step 6. The destination folders specified in excel step 1. should contain all the password protected PDF, as shown below.

Now you can tested these Password Protected PDF files by opening it using the password that you had specified in Step 1.

Please leave me a comments if you like this post. Like it if this help you to save some time in automating some of the boring task.

 

Posted on

Solving “insecure string pickle” in youtube-dl

I am trying to use youtube-dl to download something for my missus, and the error “insecure string pickle” issue is preventing the video being downloaded. After a few hours of searching the internet finally the following blog solved my problem.

The solution is quite simple:

brew install libav ffmpeg rtmpdump

Just to note my system is Hackintosh running el-capitan with homebrew installed.

Posted on

Send message to LED matrix using Bluetooth

The next iteration of the LCDMatrix in the earlier post is to add a Bluetooth module HC-05 to the Arduino. This will allow us to send message to LED matrix using bluetooth.

The bluetooth module will need to be connected to the Arduino via the following:

  • Pin 2 is connected to the RX of HC-05
  • Pin 1 is connected to the TX of HC-05

Once this is done, we need to initialise the Bluetooth module to ensure that we can connect to it. In this demo we are using Android app called Bluetooth terminal which allow us to connect to the HC-05 bluetooth module.

You can see it in action in the following clip.

If you are interested to get the source code and the detailed diagram don’t hesitate to let me know.