We explore all kinds of technologies, starting from programming, electronics ending in the photography sector. A bit for everyone.

Wednesday, January 17, 2018

How to: MANY toggle switches on 1 pin of the Arduino


Couple of years ago, I had a project in mind that involved 10 toggle switches that needed to to be connected to the Arduino as the brain of it. So, seeing that I need 10 different pins on the Arduino, I knew that I could devise something up, so that it just uses 1 to 3 pins on the Arduino. My idea is to create an adapter that will convert the toggle switch into a momentary one. And this is exactly what I've created and something even better.


Here's the final waveform that I need to deliver:



Seeing the waveform, you can notice that we need two monostable circuits, one on the rising edge and one on the falling edge to generate two pulses, each when the switch changes position (from OFF to ON or from ON to OFF). So, I constructed this beautiful four transistor schematic that does the exact same thing. Notice that the schematic only consists of transistors, there are no ICs.



NOTICE: This schematic is the correct one, I have removed a resistor from the schematic that I showed on YouTube!

Up there is the toggle switch as an input device and down there is the LED as an indicator. You could directly connect it to a pin on the Arduino. You would need to build a PCB for every switch. Always have in mind the type of the switch (on this schematic, it's the DPST switch, but you could use any other type of toggle switches, as long as you supply opposite potentials on both the bases of the transistors). The length of the pulse is adjusted according the capacitors (on the schematic 47uF). This brings the possibility of connecting as many boards of these as you like in parallel to just one of the pins of the Arduino.

Here's an example waveform with two different toggle switches and how it is possible that the Arduino can detect which one is turned on/off.




Here's the PCB for it!



Because this is done only using transistors, it's very reliable and fast enough, but it might not be so precise in the timing (It's good enough for the arduino, btw). But if you want to have something that is very precise in the timing, you could use this NE555 Schematic that I devised too.


In most cases you won't need it and it's going to cost you way more.

The PCB that I showed on YouTube is not complete, I needed to put few more pull-down resistors in place, so don't go off and copy it from there. I suggest building your own PCB from this schematic. Maybe sometime in the future I'll update the PCB and upload it here.

I have build both of the schematics on PCBs and they work just fine.
If you have any questions feel free to post them in the comments.
Share:

Monday, January 1, 2018

Color Palette - The Manim

Happy New Year everyone! (if you are reading this in January, at least)

Hi!

As an after-party, writing a bit of code is just enough... :)
Color palettes are very important and essential piece of graphics design. They contribute to the look and feel of the piece. Artists put a lot of effort into creating palettes.
So, I wrote a little script in python that goes through the default color palette and draws the palette on squares, just so we can have a look into the colors whenever we need to pick one.

HERE's a video of that animation.


Taking a look into the script and understanding it will give you a good amount of knowledge that can get you started with coding in the Manim.

This is it for today, I'll see you next time!
Share:

Wednesday, December 20, 2017

Writing text with the Manim

Hi!

In my previous blog posts, we were setting and running our first example animation with the engine called 'Manim'. The example animation only consisted of drawing a square and transforming it into a circle. This time, I want to try out the so called 'WriteStuff' scene in the example_scenes.py. This scene, for the first time, renders a text with cool vector animation that is unique to 3Blue1Brown.

What's the problem with the 'WriteStuff' scene?

So, if you try running this command:
 python extract_scene.py -p example_scenes.py WriteStuff 
to preview the WriteStuff scene, you would probably see an error that tells you that there is a .svg file missing. This error is caused by the lack of a framework called 'LaTeX' that is used to convert text to .svg files to be able to render the text with all of the cool animations. LaTeX is mentioned as a primary requirement in the readme file on the official GitHub page of the Manim. So, today we are going to install it and test it.

Installing LaTeX

HERE is a link for the setup file, install it just like any other setup. That simple.

Checking if LaTeX works properly

As Anthony Northrup talks about checking if LaTeX and dvisvgm work (it's a LaTeX tool that converts DVI and EPS files to SVG files, hence the name dvi - svg):
Once you've tried to preview/save the WriteStuff scene, you should have a file <NUMBERS>.tex in the /files/Tex directory. If you ran into issues when viewing the scene, try calling the conversion calls (found at the bottom of mobject/tex_mobject.py) manually (but with logging) from the command line. For example:
> cd /files/Tex/
> copy "<NUMBERS>.tex" test.tex
> latex -halt-on-error test.tex
> dvisvgm test.dvi -n -o test.svg
If there aren't any errors at each step, it should convert properly when running via the extract_scenes file, but the dvisvgm might pop an error.

So, what if the dvisvgm pops an error? 

With couple of simple steps you would need to replace the existing dvisvgm tool with the most recent version found HERE (you can also compile from the latest source found here). Choose the correct architecture (32 or 64 bit) and download the .zip archive. There, you will find couple of files including dvisvgm.exe.
Now you will need to use this new version instead of the included version from MiKTeX (or whichever LaTeX installation you are using). To do this, we will need to extract the zip to a folder, then add that folder to the system PATH variable. You can find instructions for doing this here. Once that has been added, you can verify the system is pointing to the updated dvisvgm by opening a new command prompt window (you may have to restart on older machines for the PATH variable to be properly updated) and use the where command:
> where dvisvgm
<THE ABSOLUTE PATH(S) OF dvisvgm IF FOUND>
If the folder you extracted the zip to is at the top, you are ready to test again, otherwise you'll need to fix the PATH.

Now, if you try just the last command, it should work properly converting the dvi to svg.

Try running the preview command again and it would hopefully work:
 python extract_scene.py -p example_scenes.py WriteStuff 


That's it ! You can now render any text you want !
Share:

Monday, December 18, 2017

The Manim -- Follow up

Hi!

This is a follow up blog post for the Manim (the animation engine for explanatory math videos). Today we are going to save the example animation.

So, in the previous blog post, I left you wondering how to save the actual example animation.

After you have done every step carefully and methodically, I assume you can run the command and preview the example animation 'SquareToCircle' in low quality movie format:
 python extract_scene.py -p example_scenes.py SquareToCircle 


Now to actually save it... First, find the 'constants.py' file and in it, change the MOVIE_DIR from
 os.path.join(os.path.expanduser('~'), "Dropbox/3b1b_videos/animations/") 
to 
"<your absolute/fixed output folder path>" 

For example:  "C:/Videos/" 

then try running the command: (Note: that instead of -p we write -w)
 python extract_scene.py -w example_scenes.py SquareToCircle 

You may see an error saying that there is no 'ffmpeg' command. That's because ffmpeg is a framework that needs to be installed and that's fairly easy to do. Just follow the instructions HERE.

After downloading the ffmpeg and adding it to the environmental path variable, you should be good to go. Run the command again and you should see something like this:



Explained by anthonynorthrup314 (Huge shoutout to him for correcting this blog post):

The error you are seeing at the end: The system cannot find the path specified is because it plays a chord when it finishes rendering a scene, you can find this method at the top of the helpers.py file: play_chord(*nums). It tries to call a program play, which isn't installed on Windows. Installing SoX on Linux fixes the problem, but I haven't tried installing it on Windows to actually prove that it will fix the issue. But, in the end, it's nothing to worry about.

Wala!  Now you have created your first movie via The Manim! Congrats!

That's all for today, I'll take a look into the actual code now...
Share:

Animation engine for explanatory math videos -- The Manim

UPDATE: This is an out-dated tutorial, I'm sorry. I'm working on new tutorials...

 
Hi!


I want to make animations for explaining programming concepts and, of course, upload them on my YouTube channel. Watching 3Blue1Brown's YouTube videos, I was wondering how does he make them? If you don't already know, he has a animation engine that he built with python. NOTE: Don't rush it, you are going to have a lot of problems if you do so. Here's the link to his GitHub repository.


one more NOTE: It's going to take you a fair bit of time (couple of hours) setting and learning things up. So, first ask yourself is it worth it! Not saying to discourage, but to warn...

In the process of actually starting it, I downloaded it in my Python27 installation folder (btw, for this to run properly, you need Python 2.7 not the newer 3.6 version). When installing Python, is a VERY good practice (and that's what I did for this tutorial) to add it to the environment path variable (just google - add python to path). When you have downloaded Python27 and the Manim project folder, you can see the required modules for running it in a text file called "requirements.txt". You can see there all of the versions of the modules that are necessary. Here's the catch. You will have a lot of issues with it.

First of foremost, you need to have pip installed, because pip doesn't come with Python27.
The easiest way to install pip (and that's what I did) is to download THIS module in the python folder and run it using the command  python get-pip.py 

Now you have pip installed. The next step is to install every single required module. Here's the catch that I was talking about. In the readme file on the Manim GitHub repository, it's mentioned that you can do this :  pip install -r requirements.txt  but I don't recommend it! Of course first you would need to  cd Scripts  and then using pip, install all requirements manually, by hand and don't forget the version [ EX:  pip install colour==0.1.2  ]. Read them from the text file, one by one and install them. If you have any problems with numpy and scipy, download them individually from HERE as .whl files in the Scripts directory and just run  pip install <the .whl file name>  . This should work without a problem. Of course, keep in mind that you would need to install numpy before scipy.
I would recommend always installing numpy and scipy from the .whl files, because even though I had them both installed, the Manim wouldn't run... As soon as I installed them from the .whl files, everything was working properly.
The last module (aggdraw) is going to require having THIS C++ Compiler Package for Python 2.7 and GitHub installed to be able to clone the repository. I had the GitHub installed on my PC, but if you don't you may try manually downloading and extracting the directory from the link given in the requirements.txt file -- [GitHub link] -- and then manually using pip to installing it. It's a nice thing to have GitHub though, I recommend it every day of the week.

If all of the requirements were installed successfully, you are good to go.

I'll leave you here today...

The next phase is running the Manim from it's project folder
(for me, it's - C:/Python27/Manim - you should be in the folder where you have downloaded Manin)
  python extract_scene.py -p example_scenes.py SquareToCircle  

Thanks for all of the corrections that were suggested by anthonynorthrup314

Next time, will attempt to save the same example animation...
Share:

Friday, September 22, 2017

Arduino: Char Array Problems

While programming an embedded system based on ATmega328p, I have encounter some char array problems in the C programming language.


I had a char array of exactly 8 chars ending with /0:
char a[] = "///////0";
It had trouble reading a[0] many times. For some still unknown reason, when I had:
char a[] = "10000000";
it would corrupt some memory addresses close to the array and it never work as I wanted. The problem is not the '/0' at the end. '/0' it's NOT the null terminator (NUL character in ASCII). The null terminator is '\0'. I tried this with both, the C compiler in the Arduino's native IDE and the C compiler in the Atmel Studio 7 (with the Visual Micro installed) and it was the same exact thing. So, what's wrong? I still don't know, but I'm writing this blog post, because I fixed the problem by adding a random character in the front and in the back that would be never read by any actual code. Just for storing purposes. I can't reveal the whole code, but because of the trouble that I went through I don't recommend using char arrays now at all... :D

The solution code for me was:
char a[] = "/10000000/";

- Mitko
Share:

Tuesday, September 19, 2017

Make a Shutter Release Indicator for any camera!

Following my previous post, I have done and tested a little schematic for a indicator whenever the shutter actuates (whenever the shutter is released). Check the demo video here.

So, we know that the CENTER PIN on the hot-shoe is connected to the GROUND whenever the camera takes a picture (when opening and closing the liveview, that doesn't happen). This automatically triggers the flash. There is a little catch that I explained in the previous blog post.


But this schematic is just good enough for successfully indicating a shutter release. 

As I discussed in the previous blog, the camera keeps the CENTER PIN connected to the GROUND until there is no current flowing to the CENTER PIN i.e. the flash is already triggered. That makes the situation a little bit complicated, so to workaround this issue I have put Q1 transistor to pull the current through the LED to the ground whenever the flash is trigger. That way the LED will flash just for few milliseconds. (I think the schematic is understandable, for any questions, leave them in the comments.)

Some schematic notes:

  • The switch in this virtual schematic acts as the flash triggering IC in the camera. There is no switch in the real world.
  • D1 is the LED which indicates the shutter release. You can put a series resistor for current protection, but because that's just 3V and a small pulse, I had no current limiting resistor.
  • R2 is a current limiting resistor for both, the Q2 and when the shutter is released, the R2 is directly connected to GROUND.
  • R1 is a current limiting resistor too.
That's it! You now have a shutter release indicator that could be used for wireless remote triggering!

Camera used: D5200
Software used to create the schematic diagram: Circuit Wizard

See you next time!
- Mitko
Share:

Contributors

Powered by Blogger.