Sunday, December 16, 2018

Virtual Bread Board: Simulate Your Trip to the Land of Lunetta

Howdy again. 

Another post for the world of AudioDIY and Arduino.

This time let's look at a new Simulator I have been messing with called Virtual Breadboard or VBB.

The background:

I stumbled upon VBB while messing around with unrelated programming at my day job. It's a really cool SIM but not nearly as straightforward to use as say Tinkercad--VBB does a lot more, but with that comes more complexity.

However, the more I use VBB the more I like it.

And, I wanted to write down how I got VBB to work with the Arduino IDE.

Hence this post.

Goes like this:

Tinkercad Circuits is cool but lacks a wide range of CMOS chips to play around with. And you know how we Audio DIY folks love CMOS--the 4051, the 4049, the 4066--on and on! they are our friends.  It'd be nice to have more CMOS SIMs at our fingertips.

For this let's take a look at VBB:

 First the bad news:
  •  For SIMS using Arduino, VBB costs $30 per year. The free version doesn't support Arduino. That may not break the bank--and once you get VBB going you get a hell of a lot for $30 a year--but it's notable that it costs anything at all considering that TinkerCad Circuits is free. But then, this Blog is free as well. Boing! Take that!
  •  VBB is only available through the Microsoft Store for Windows OS. I try to remain positive at all times and as a Linux guy I look at that like this: I figure VBB is maintained by one or two programmers (?), working out of a garage or basement maybe, so don't expect VBB to have an huge army of programmers porting VBB to every platform out there you can think of.  So, Marky Mark: Swallow your pride and get Windows going....
  • VBB is not documented well by 3rd parties on Youtube, including some baffling tutorial videos that I couldn't follow at all. I mean what the hell is this? it seems to demonstrate VBB and Arduino, using methodology pretty far from the VBB tutorial, and using an Atmel chip that the current software doesn't seem to contain. hello?
  • VBB almost exclusively simulates digital circuits, not analog ones.  There are no op amp chips for instance in VBB. There are in Tinkercad and Fritzing. This makes VBB good for banging together things using CMOS and 74xx chips, but not analog simulations of VCAs for instance. However there is a "function" component in VBB that can be used to (say) add two voltages together--op amp type stuff. Really, that alone is very cool indeed. Maybe a topic for another post?
 Now the good stuff:
  •  VBB includes a whole crapload of CMOS chips to mess with, along with function generators (squarewave only), voltmeters, PWM,  D to A, and other goodies very useful to Audio DIY folk and Lunetta devotees like me:
This is only some of it!!!

  • Like Tinkercad Circuits, you can program your SIM with the Arduino IDE (once you set things up correctly, more about that in a bit.) 
  • VBB doesn't bog down as badly as Tinkercad under normal to heavy use.
  • Unlike Fritzing, VBB is currently maintained.
  • VBB includes a few extremely useful I2C chips for Audiodiy in its SIM mishpucha including the Maxim DS1803 digital pot. Very Nice! 
  • Since the SIM runs off compiled Atmel binary code, if you can find the library for whatever you are doing, and can successfully compile your sketch, you can probably use it in your SiM. This is worth the cost of admission alone! 
  • I wrote to VBB tech support a few times now and the tech there got back to me superfast--like, a few times, within an hour.  Wow! that's unusual in the tech support world!!  Hats are off!

So how to get this set up with Arduino IDE?  VBB is natively a java app, not C, so you have to tweak things a bit to get the good old Arduino IDE C programming going.

This tutorial explains how to do it; but I reiterate and perhaps simplify it a bit here...so:

Here's the quick way to get this software set up to program using the Arduino IDE--

  • You have to have Windows 8+; I use Windows 10 Pro.
  • Download VBB from MS store and if you want to part with dough (I did--it's worth it) purchase the $30 a year Proplan.  The free version of VBB doesn't support Arduino...
  • Create a username and password for the VBB "cloud site", virtualbreadboard.io. You will need these credentials later to launch the desktop version of the software.
  •  download the VBB desktop app here.  For this blog post, we are going to use the desktop version, not the cloud version, of the software.

The VBB Cloud app. Cool, but for this post I focus on integrating the Arduino IDE with the desktop version of the app


Next:

  • Download and install the latest Arduino IDE on the Windows 10 system you will use for your VBB simulations. No, VBB doesn't have the Arduino IDE "built in" the way Tinkercad or Fritzing does....you have to install it.
  • On this same Windows system, make sure if you double click a .INO file the Arduino IDE opens, not something else like Notepad or Wordpad.  So create a file called "test.ino", save it, double click on it, and see what happens.  If double clicking an INO file doesn't open the Arduino IDE, follow the directions here to fix it so it does.
  • Create a basic sketch in Arduino.  It can be anything--blank sketch, with setup and void and nothing else, that is good enough. For what I am writing here, I use the blink demo sketch as proof of concept.  I call it blink3.ino since I already had a blink.ino file on my HD.




In the Arduino IDE, issue the command Sketch > export compiled Binary:




  • Give the hex file/project folder/ino file a name salient to your project, again I called this "Blink3"
  • Store the compiled hex file on your system's hard drive (I use Dropbox--same thing)
  • Note where you store the hex file.  Write it down in notepad for instance. You will need to find this hex file again later.
  • Open VBB desktop, enter the username and password you crafted when you paid the $30.
  • When running VBB for the first time, I got a bunch of warnings that VBB.exe isn't certified by MS, might be a virus, might be ransomeware etc. Sorry. Keep going.
  • Once open, make sure your VBB SIM is in Single panel mode. See the screenshot below. 


This icon is found in the top right of the main VBB screen.



  • Create a new VBB sim project, add a Arduino Uno, an LED on PIN13 and a 1K resistor like this. You can get more information about adding parts to a VBB SIM project from this tutorial; it's pretty straightforward.  Note we are using pin 13 connected to the resistor to the LED anode.








  • Left click on the UNO board in the SIM, selecting it.


  • In the VBB panel on the right, go to the properties dialog for the UNO and make sure "Java App" is set to sleep and "AVR App" is set to "Arduino IDE monitor".  This is on the right part of the screen.  You left click on the "..." icon to change that:





  • File > Save the VBB SIM to some location (doesn't really matter where) as "Blink3" and note its location.


Now, the trickiest part of the whole process:


  • Close VBB after creating your SIM project.



  • Open Windows File Explorer:  Right click Windows icon >  left click "File explorer"

  • Find the files that VBB created above.

  • The files are going to have the extension .SIM, .VSM. and .VBB

  • Copy all 3 of  them to the location of the Arduino ino and hex files you created when initially making your blink3 sketch.  It all has to be in one folder!

  • Important--the .SIM, .VSM, .HEX, and .INO files have to all have the same file name.  Not the same extensions obviously; and the exception here is the .VBB file. So if this isn't working, close all apps, reopen file explorer, and make sure all files that end with .ino, .hex, .sim, and .vsm all have the same filename; if not, rename things.  The screenshot immediately below gives you an idea of what I mean.



Now you see why you needed to note each folder's location right?

OK with everything in one directory we can actually run the Simulation:


  • reopen the VBB app
  • File > open > browse to the SIM VSM file you just copied, so in my case I am opening blink3.VSM

  • Run your SIM by clicking on the power icon.


Run Icon is in the top left corner


The LED should blink, It did for me!  Yes you programmed this blink simulation action by creating the hex dump and then having VBB read it--you programmed the SIM with the Arduino IDE.

Cool!!!!

Now make sure you can change things:

  • Go to your Arduino IDE (It's outside VBB--you have to have both running at once--you can alt + tab to it) and change something.  Say make the "LOW" 100 MS sleep but leave HIGH at 1000:


  • In the Arduino IDE, Reissue the command Sketch > Export Compiled Binary




  • This overwrites the hex file you created at the beginning of this whole process.
  • You don't have to do anything to VBB--just leave it running. The blinker rate is now 1000 on then 100 ms off, give or take.  The code change will be visible almost immediately--
    "Export compiled Binary" is essentially the same as uploading code to a "real" Arduino from your PC.
So here is in a nutshell what you do to change either the components in the SIM or the sketch controlling it:
  • Make changes to the IDE and issue Sketch > export compiled Binary
  • Make changes to the VBB SIM project and file > save 
  • Run the SIM in VBB.  
  • If you're just changing code, you don't have to stop the VBB Simulation; if you want to swap out parts on your virtual breadboard, you will have to stop the SIM, make your changes, and restart the SIM.
  • In any event as long as everything "lives" in the same folder, one component will be in synch with the other.  Go A's!

UPDATE: To further understand VBB, I simulated a 5 Channel 4051 CMOS based audio/CV switcher. Incoming 0-5V CV determines which channel at input is sent to a common output.  This is a very simple circuit if you use an Arduino and was easy to implement using VBB. In a future post I will give more details but the sim looks like this--and I'll try to build a "real" module, that I can use in my modular synthesizer, based on this SIM, in the next few weeks.

UPDATE TO UPDATE!  4051 module is done, heavily based on the 4051 VBB sim you see here, and works great!  See the post here!!!

A slider is used to send 0-5V to A0 of an Uno. 0-1V connects in 0 to the common out; 1-2V sends in 1 to out, and so on.

UPDATE: I got confused by how to see variable values in VBB, display things to the serial monitor, etc. but I was overthinking things. It's easy. Hook up the VBB terminal to RX and TX ports as shown below,  RX to TX and TX to RX, set everything to work at 57600 baud, and then use serial.begin etc. for Arduino as documented here. Works great!  



OK enough for one post. Next time (or one of these times soon) I will have more SIMs to show--a CV to 4066 switcher and a trigger delay module, both of which I need in my DIY modular, like, right now.

Until next time, breathe the fumes, but only the simulated ones!




No comments:

Post a Comment

Saving OTAs--One Chip at a Time--a Simple Hack

Quick background:  what the heck is an OTA anyway? It's a type of IC. For audio and especially synthDIY you see Operational Transcondu...