NodeBot Adventure Time: Crank the Tunes!

As I discussed in a previous post… I was trying to get my Arduino to play music. I attempted to build and use an Arduino Wave Shield and FAILED. But yet.. I have managed to overcome such a feat and now I got my Arduino playing music. And thats not even the best part. The real icing on the cake is that… (wait for it, wait for it) …. IT IS ALL DONE USING NODE.JS! (Crazy right? I thought it was almost impossible).

How can you turn your Arduino into a music player using Node you ask?

Well first you need the right shield. The one I bought is from a third party seller (not from Adafruit or Sparkfun), but actually from a company on ebay. It is compatible with the Sparkfun MP3 Shield library, so you really could buy either one for this example to work (the one I bought is cheaper though).

300px-mp3-tf

Though I have provided the Sparkfun MP3 Shield library, we know that Arduino sketches are not written in Node… so let me spill the beans on how its done:

The answer is Paul DeCarlo. Paul is also a Technical Evangelist who helped put this together for me when I was in crisis(WHOOP WHOOP! Go Paul). Using Serial Port, he was able to communicate to the Arduino Shield using Node with these 7 simple steps:

Screen Shot 2016-03-19 at 5.40.38 PM

Before you can jump into it though, you will need a few things set up. First, be sure you have a microSD card inserted into the MP3 Shield, with file names such as track001.mp3, track002.mp3, track003.mp3. (If you do not format your file names as such, the shield will not read the file names properly and you will not be able to play any tracks. And yes those are zeros). Secondly, you will need to be sure you have the Arduino IDE installed onto your computer; you will need it for Step 4. And lastly you will either need a pair of headphones or speakers to plug into the shield, or else you wont here much of anything.

Some extra tips and hints:

  • In step 4 it says to use the MP3Shield_Library_Demo sketch, but considering the Sparkfun MP3 Shield library does have other sketches, you have options and you can test the code with the other sketches
  • In step 5 to find your port value go to your Arduino IDE => Tools => Port and you will see the port to your Arduino listed. If you are using a MAC, the port value will not be a COM value but rather look something like this:  /dev/tty.usbmodem1411  or  /dev/cu.usbmodem1411. If your port value shows a cu. , replace it with tty. in the code or else your Arduino will not be found.

You can find Paul’s code here. Feel free to download it and have a blast jamming out. Also you should totally check out Paul DeCarlo’s page for more info on how to do IoT and various other hardware projects.

SideNote: As the NodeBot Adventure posts have continued, I have not yet told you how all these pieces are coming together. But soon, I promise you I will reveal the final project. Stay tuned.

Standard

Speech to Text with Project Oxford using Node.js

Microsoft’s Project Oxford’s APIs are a bit more complicated to use than what many are expecting, especially when using Node.js! The Project Oxford SDK does not provide code in Node for all APIs, i.e Speech to Text. Using the documentation provided online for REST API’s can be a bit confusing, but I think I can help out a little. Note that this API takes in a pre-recorded wav file and listens for speech.

So your first step is getting your Access Token.  You need to make a POST request to https://oxford-speech.cloudapp.net/token/issueToken . The body of your POST request must include the following as x-www-form-urlencoded data:

  • grant_type: ‘client credentials’
  • client_id: <whatever you would like to call it>
  • client_secret: <your api key from the project oxford site>
  • scope: ‘https://speech.platform.bing.com&#8217;

You should receive a JSON object with an access token, a token type, an expiration time (in seconds) and the scope.

From here your next step is to make another POST request to https://speech.platform.bing.com/recognize/query with the following parameters:

  • version: 3.0
  • requestid: <this can be any unique GUID>
  • appID: D4D52672-91D7-4C74-8AD8-42B1D98141A5  (this is the magic value for this to work)
  • format: json
  • locale: en-US (or whichever language you prefer)
  • device.os: <which ever device you are using>
  • scenarios: ulm
  • instanceid: <this can be any unique GUID>

You can get newly created GUIDs for your instanceid and requestid from various online sites or an npm module named guid made to randomly create them. The body of your post must be waveData. And your Headers are as follows:

  • Authorization: Bearer<authorization token we received in the first post>
  • Content-Type: audio/wav; samplerate=8000  (be sure the sample rate matches the wav file you are using)

Testing the API using an app like POSTMAN  would look something like this:

POST https://speech.platform.bing.com/recognize/query?scenarios=catsearch&appid=D4D52672-91D7-4C74-8AD8-42B1D98141A5&locale=en-US&version=3.0&format=json&requestid=b2c95ede-97eb-4c88-81e4-80f32d6aef74&instanceid=106a4690-b664-ca61-addb-cdc705560791&device.os=osx

 and then adding the headers of course. If you are using a tool like request in your app.. then your POST request may look something like:

Screen Shot 2016-02-11 at 4.37.13 PM.png

Note in this example the accessToken is a variable rather than the long accessToken given to you earlier. This should help make the code a lot cleaner.

For a good example on how to use this Project Oxford Speech to text check out this github gist by Luke Hoban. He does a great job of making all this of this into one seamless function.

Good luck 🙂

Standard

NodeBot Adventure Time: I Failed. Boo-hoo

For a good 2 hours, my life seemed to come to a halt because I failed. A HUGE element of my project will not work and now I am stuck. As I mentioned earlier, I soldered an Arduino Wave Shield. Actually, I soldered two! And neither are functionally correctly.  I keep getting the error code:

Error: Card init. failed!
SD I/O error: 1, FF

I have resoldered, rewired and recoded almost every part of this project and nothing has seemed to come together. But I realized this is apart of my job for things to not work the first time, for things to completely blow up in my face and to have to completely restart and rework my whole project. This is how great developers are created, their moment of failure. So this blog post is really just a reminder for all developers out there: If it doesnt work the first time.. Don’t give up. Seek help and find another way (A potentially better way).

Stay tuned for the next step of my journey, and how I reworked my NodeBot.

Also If you have any advice for getting my Wave Shield to work, feel free to email me or comment on this post, with possible solutions. I would love to figure out what I could have possibly been doing wrong.

 

 

Standard

The Suspense! The Horror!… The Soldering Iron?

Just wanted to share:

Yesterday was my first time using a soldering iron and it was so intense! I don’t have a steady hand… So putting together an Arduino Wave Shield was not the easiest thing for me. I was so scared I would mess it up… Eventually I got the hang of it, and became less and less nervous. And I was able to make this:

image It was quite a blast, pretty easy when following the directions! Now hopefully I can get it working with my project correctly.  Wish me luck!

Standard

NodeBot Adventure Time: Getting to know a Breadboard

The Adventure Time series will be my series of creating a big project. I will talk about the different technologies I use, the many problems I encounter and the solutions I find. So stay tuned to see what is to come.

I am aspiring to create two NodeBots! I don’t want to delve into what the finished product will be.. because then you wont follow a long the Adventure Time series to see how it all ends, however I will give you a little detail:

  • Both of my NodeBots will be created using an Arduino
  • They will have similar functionalities but they will serve different purposes — two different age groups as well
  • They will both require additional hardware
  • And most of all they will be a lot of fun

Moving on… When using an Arduino and adding additional hardware and creating a circuit of some sort, what is needed? A breadboard. If you are like me, and only majored in Computer Science where circuitry and small components of Electrical Engineering were not covered, then that means you have no idea what a breadboard really does or how it really functions. Do not worry you are not alone, I was just you five minutes ago! But now you can be me (five minutes later) and have a better understanding of breadboards!

halfbb

 

So here is your breadboard!  The three parts we will focus on are the Power Rails, Terminal Strips and DIP Support. 

  • Power Rails: On the right and left side of the breadboard are two rows labeled with a ‘+’ sign and a ‘-‘sign. These four rows are used for exactly what they seem like, power. Breadboards do not have their own power supply, so usually these strips are used to connect the breadboards with an Arduino, a battery pack or any other form of power supply. Keep in mind that when you connect your power supply to one of the power rails, it has only added power to one side of the breadboard. You can connect both power rails and have the whole breadboard using that one power supply by doing this: 518c07b8ce395fd064000000
  • Terminal Strips: The terminal strips are the horizontal numbered rows of holes in the middle of the breadboard.  Underneath these holes are metal strips used to electrically connect all wires in the same row. So for example, any component placed in row 8 column a is electrically connected to any component placed in row 8 column d. However, neither of the two components are connected to a component placed in row 8 column g. The gap in the middle splits each row, causing only five components to be electrically connected at one time. Any components that are in the same row and are in columns a thru e OR f thru j are electrically connected, but not the whole row.
  • DIP Support: The gap in the middle of the board that splits the rows in two is the DIP support. It is used to support DIP chips: 518d22f8ce395f5d51000000 I feel like putting this into my own words will be a bit complicated, so here is a quote from Sparkfun:
    • “These DIP chips (salsa anyone?) have legs that come out of both sides and fit perfectly over that ravine. Since each leg on the IC is unique, we don’t want both sides to be connected to each other. That is where the separation in the middle of the board comes in handy. Thus, we can connect components to each side of the IC without interfering with the functionality of the leg on the opposite side.” (Sparkfun, https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard)

And that concludes my basic training for learning about them! Here are some tutorials to get you started on using them:

  1. http://www.instructables.com/id/Breadboard-Basics-for-Absolute-Begginers/
  2. https://startingelectronics.org/beginners/start-electronics-now/tut1-breadboard-circuits/
  3. http://computers.tutsplus.com/tutorials/how-to-use-a-breadboard-and-build-a-led-circuit–mac-54746

Also if you are really hoping to delve into circuitry, it is important to understand how to read and interpret schematics. Schematics are diagrams that are used to design and build circuits. If you want to learn more about it, check out this link!

Standard

Learn Something New: How to Create a VSCode Extenstion

Visual Studio Code, my current IDE of choice, has become a tad bit cooler because I contributed to it. (JK, I’m not the only reason)

Before I delve into my contribution, lets discuss what Visual Studio Code is. Well.. VSCode is the newest cross platform code editor provided to you by Microsoft. VS Code contains many tools such as debugging tools, Git control and etc. It is also customizable, in which you can change the shortcuts, theme and preferences. And to top it all off… VSCode is FREE! I tend to use VSCode for my Node projects; I have also used it for TypeScript and .NET projects.

(VSCode is not to be thought of as a replacement for Visual Studio, so please if you are looking for more tools and features, keep using Visual Studio)

VSCode also contains extensions that can be downloaded from the Visual Studio Marketplace (this is where I come in), and I created one. I created a StackOverflow Search extension that allows you to conduct a StackOverflow Search straight from VSCode. Check It Out 🙂 Extensions can be made by anyone and I am going to give you a brief overview of how! If you need help downloading and using extensions, go to this link for help.

First I used the Yeoman generator extension to get up and running! Whether you are using TypeScript or JavaScript to code your extension, the Yo generator will provide all the files needed to create a successful extension. More info on how to get started with the Yeoman generator extension can be found here!

I did my project in TypeScript. The object orientated nature of TypeScript makes creating different functionalities of the extension pretty easy. To get you started on how to get up to speed with a TypeScript extension here is a quick and simple Hello World example. This is actually what I started with and moved on from there. If you want something a bit more advanced try try this.

Your next step is to publish to the Visual Studio Marketplace! Wanna know how? You will need to use vsce, the publishing tool! All the steps are clearly written out here. You will need to sign in to a Visual Studio Online account, so be sure to create an account if you don’t have one.

And boom you are all done and ready to go. My advice before creating an extension is be sure to check that your idea doesn’t already exist in the marketplace and also… check out any npm modules that may help you achieve your goal a lot easier! I definitely used one in my project 🙂

Have any questions? Feel free to contact me!

 

Standard

Do The Unthinkable: Deploy your Node.JS App on to Azure

As a consistent learner, I went out and researched a way to upload a Node.js web app on to the Azure cloud. And boy oh boy did everything look pretty complicated. But after looking through my findings and experimenting on my own, I realized it is actually pretty easy. So lets jump right in and get you going.

Step 1:Log on to manage.windowsazure.com and either sign in or sign up!

Step 2:  In the bottom left corner, you should see a BIG plus sign that says NEW. Press it.

Screen Shot 2015-11-04 at 5.25.30 PM

Step 3: Once you press the New button, select the Compute option, then the Web App option and lastly the Quick Create option.

Screen Shot 2015-11-04 at 5.36.46 PM

Step 4: Fill in the name of your new azure site and choose the location for your app service plan. (Most likely your default setting will work just fine)

Screen Shot 2015-11-03 at 4.37.11 PM

Step 5: Back in the homepage, choose your web app. A menu of several links should pop up and at the very bottom it should say: Set up deployment from source control

Screen Shot 2015-11-04 at 5.37.25 PM   Screen Shot 2015-11-04 at 5.38.03 PM

Step 6: You will now have several options to choose from, but in this blog … I will be only be demonstrating two: Using the Github or Local Git Repository option.

Screen Shot 2015-11-04 at 5.38.11 PM

Using Github: Simply press the Github option, log in to Github, authorize Azure to have access to your repository and                choose the repository you would like to upload to the web app.

Screen Shot 2015-11-03 at 4.47.43 PM

Using a Local Git Repository: Choose the Local Git Repository Option and from there you will be directed to a page with          directions to connect to the azure portal through command line. (Keep in mind that we are creating a new app on Azure              so you can skip the step that says “or clone content that’s already on app” because… well, nothing is on your web app              yet).

Screen Shot 2015-11-04 at 5.38.58 PM

When adding your remote Azure repository you can copy and paste the link for your repo at the top of the directions

Screen Shot 2015-11-04 at 5.40.24 PM

Once you push your code to the Azure repository, it will automatically show up on your portal screen and you will see this          image when it is done:

Screen Shot 2015-11-04 at 5.41.33 PM

***Be sure that whenever you make changes on your local repository, you continue to push to your azure repo!

Hope this helped you deploy your site on Azure! got questions? Ask in the comment box or DM on twitter. @nowayshecodes

Standard