Blog

  • Online Components Shops — India

    Online Components Shops — India

    I surveyed a lot of online shops today in my country. I was looking for shops that sells Electronic Components at cheap rates. I got the following list of sites. This is surely not exhaustive but are the ones that I thought were good:

    S.NoWebsitePricingAvailabilityRemark
    1http://www.electroncomponents.com/HighLow 
    2http://www.evelta.com/Very LowMedGood Site
    3http://hobby2go.com/Very High  
    4http://in.element14.com/HighVery HighBad website for small Purchase.
    5http://www.onlinetps.com/Very LowHighGood Site
    6http://www.digikey.in/LowVery HighWholesale
    7www.vishaworld.com/MedMedSlow Website
    8http://tronixkart.co/HighLow 
    9http://www.anandtronics.com/MedVery Low 
    10http://in.mouser.com/HighHighBranded only
    11http://www.componentsindia.com/ Very LowPoor site
    12www.dnatechindia.com/HighVery Low 
    13http://nex-robotics.com/MedHighGood Site
    14http://www.frugal-labs.com/Low Not a component site
    15http://hacktronics.co.in/LowMedModules only
    16http://sonlineshop.com/Very LowHighGood Site
    17http://www.technofreek.com/MedVery Low 
    18http://www.roboshop.in/MedMedKits only
    19www.digxtech.comLowMed 
    20http://www.mgsuperlabs.co.inMedMedKits only
    21http://www.probots.co.in/Very LowMedGood Site
    22www.kitsnspares.com MedVery Low 
    23http://www.nskelectronics.in/Very HighLow 
    24http://www.rhydolabz.com/HighLow 
    25http://ventor.co.in/Very LowVery HighGood Site

    The availability that I am talking about was checked for the component that I needed. I finally arrived at the 6 of the best sites from the above.

    1. http://ventor.co.in/
    2. http://www.evelta.com/
    3. http://www.onlinetps.com/
    4. http://nex-robotics.com/
    5. http://sonlineshop.com/
    6. http://www.probots.co.in/

    The above seem to be the cheapest of the 25. Each of the top 6 has its own merits and demerits.

    http://ventor.co.in/: This site has got a very high availability but it is costlier than the rest. It charges a Minimum Handling Charge of Rs.150.

    http://www.evelta.com/: This site is moderate in all respects. I did not pay much attention to this site but the rates are almost like ventor and sometimes lesser.

    http://www.onlinetps.com/: This is the site that I like the best. It is costlier than evelta slightly and atleast twice as costly as sonlineshop. But it charges only Rs. 50 for shipping and the Minimum order limit is less. It has the highest availability after ventor. It is a very good source for connectors. But it charged me Rs.70 extra as surcharge for online payment which was disappointing. I don’t know if others will do it too but I continued with the payment because the USB cable and HDMI cable was cheap and worth paying the extra 70.

    http://nex-robotics.com/:  It too has a good availability and the prices are similar or slightly lesser than onlinetps. I don’t have any idea about its shipping charges.

    http://sonlineshop.com/:  Extremely cheap. In fact the cheapest of all but its main problems is with buying resistors. Some of the resistors have a minimum order quantity of 100 which is not know until you checkout!!!  I feel it might be  a software bug as the minimum quantity sometimes specified in the site don’t match with what the checkout expects. But the prices are amazingly low. It wouldn’t hurt buying it all if you can find all you need in the same shop itself. Shipping charges is Rs.100 min which is more than onlinetps.

    http://www.probots.co.in/: Not exceptional when it comes to availability but the things which are available are as cheap as sonlineshop mostly and the minimum purchase quantity is just 1 for most items.

  • USBPICPROG Hardware Ready..

    I finally got the things that I ordered for from the online shop last week. They took nearly 10 days to deliver the product. I have received all the items except there was one drill bit less. Guess they missed out on that. Rest of the things were in proper quantity. I would not mind it so much for in an order of Rs.1300, 10 bugs don’t matter much. But I would surely mind if the components fail.

    Last week as I was waiting for the hardware I read through the Zigbee protocol. I have read the PHY and the MAC layer. Some more is left to understand so I will blog about it next time. For now lemme blog about todays activity.

    The day started off with a decision to finish and test the hardware. So before getting on to the actual work I decided to check the board ones properly for any disconnected routes and missing drills. I found a few missing drills and completed it. Then I spend the next 5 hrs soldering it. I was doing it very slow because I kept checking the components often for correctness. I did not want to do a mistake and remove a soldered component. Doing so inevitably spoils the board. After meticulously checking for errors I finished soldering. Though one difference I find is in the capacitors. I have put ceramic instead of a type of capacitor that the board design has. I don’t know what type it is. The BOM generated by KiCad calls it Cuni Package but I did not get much information on the Internet. This capacitor has 3 legs. I hope it makes no difference with the replacement.

    Now I wanted to test the board and here came the road block. As the usbpicprog runs on a pic I  had to program it first inorder to check the board. So I planned to find a computer with a serial port and use the programmer that I had built earlier for serial ports. And this was more difficult than I thought. I could not find a PC with Serial port. This showed me what obsolescence means in electronics. What was such a common thing earlier isn’t available anymore. Anyways I have some workstations in my lab which have serial port so I will use it tomorrow and check it. I just hope that it doesn’t give me any adventures and it works in one go.

    So till then fingers crossed.

  • USBPICPROG Firmware Loading and programming

    In the previous blog I had mentioned that I had completed the hardware but I was not able to test the hardware. I had to load the bootloader into the controller. I tried doing it with my serial programmer but for some reason it did not work. Luckily I had given another Ic to my friend who got it programmed for me. I plugged that IC in the hardware and the board worked like a charm.

    Upon connecting the jumpers as specified by the USBPICPROG website and connecting the USB to the USBPICPROG hardware with the software opened resulting in some LEDs flashing. At the bottom of the software Bootloader v.1.0. connected appears. I then loaded the Firmware-0.5.0.hex into the software and clicked on programming. In about 7 secs the PIC got programmed with the bootloader.

    I removed the USB and connected the other jumper also. I reinserted the USB and started the software again and I was greeted with Your firmware is too old. Latest is 1.0.0. Consider upgrading? This being the first time that I was using this hardware I was too scared to try anything new. I was excited to use the hardware atleast once before trying anything new. So I ignored the update.

    I connected another controller on a bread board and connected the necessary pins required for ICSP. I connected it to the hardware and tried autodetect hardware and to my surprise without any more problems it detected the PIC. I could then go ahead and program the PIC. I tried programming few other PICs also and it worked just fine.

    After several use of the software the update request had started annoying me and I decided to update the firmware to the latest. I selected ok and it took me to /usr/share/usbpicprog. There was a firmware hex file which had already been downloaded without my knowledge. I selected it. Both the jumpers where still connected as against the advice from the website. The websites requires that one of the jumpers be removed to enter the bootloader mode before upgrading the firmware. On selecting the hex file it automatically started programming. On restarting the software I got a nice shock. The software said Bootloader or firmware not detected!!!

    That message scared me and I thought I was done with the firmware I need to reload the bootloader. Just as a desperate measure I removed one of the jumper and reconnected the hardware. And the hardware booted in the Bootloader mode!!! PHEW!!! I felt relieved and I loaded the older firmware. I was pretty confident now that the bootloader remains safe and can be used for rescue always. On restarting it detected the old firmware and again gave an option to upgrade. This time I noticed that the I had forgotten to remove the ICSP connected to the other PIC. I removed the ICSP pins but still kept both the jumpers connected. On selecting the new firmware like the last time it got programmed correctly this time. And reinserting the usb showed the latest firmware version at the bottom of the software.

    So I am finally set with the latest firmware and a working usbpicprog hardware.

  • Making the first PIC 18f2550 project in CODE::BLOCKS

    Code::Blocks is a very nice cross platform IDE. I had been experimenting with it and have interfaced with SDCC compiler. CODE::BLOCKS automatically integrates with SDCC and it automatically fills in the necessary toolchain executables. So I will leave this part and jump directly to the steps for building the first project.

    Steps for configuring the first project (I am writing my first project on PIC18f2550):

    1. Go to File -> New -> Project and select an empty project.
    2. In the wizard which opens up click Next.
    3. The next screen prompts for the Project Title. Filling in a name will automatically fill in the rest of the fields. Click Next.
    4. In the compiler option in the next screen choose Small Device C compiler and click Finish.
    5. The left pane must show now a new project without any files.
    6. Right click over the project and select Build Options from the pop up menu.
    7. In the Compiler Settings Tab,
      1. In the Compiler Flags Tab, select CPU architectures in the Categories Drop Down.
      2. Check [CPU] PIC 16-bit
      3. Click on Other options. Add the following text into it: -p18f2550 -Wl -m —use-non-free —verbose -V
        1. The -p switch tells the compiler the exact pic name
        2. -Wl -m is used to pass a switch to the Linker to generate the .map file in the output. This is a useful file normally suppressed by SDCC.
        3. –use-non-free is required to use the PIC header files as it is not covered under GNU license
        4. –verbose -V asks SDCC to be verbose and this helps in debugging the build
    8. Now create the first program or use any available program from the Internet and add the file to the project by right clicking the project.
    9. Clicking on build should build it and the bin folder inside the project directory should contain a hex file under the current build configuration (Debug/Release).
    10. If the hex file is not produced read the verbose output for any syntax error or missing libraries.
    11. SDCC looks for the default libraries libsdcc.lib, crt0i.o and libdevpic<picid>.lib at its default locations. If the libraries are not present in its default location you can manually specify the path in the Build Options (obtained by right clicking the project) and setting the linker search directories.
  • Quaternion Basics and Quaternion Operations

    Quaternion Basics and Quaternion Operations

    Quaternions have ushered in a significant paradigm shift in the representation and computation of rotations. This post is part of a series dedicated to exploring Quaternions and their practical applications in the context of rotation. In this particular post, we will delve into the Quaternion basics, including essential quaternion operations for working with them. Subsequent posts will explore more advanced applications of quaternions in expressing various types of rotations.

    We commence by discussing the motivation behind the study of quaternions. It is crucial to establish why one should delve into this topic, and a glimpse into its historical context can greatly enhance our understanding. In particular, exploring the history of an ingenious invention like quaternions is an essential section. Following this historical exploration, we will delve into the fundamental operations that can be applied to quaternions. These foundational concepts are vital for comprehending how quaternions are commonly employed to represent rotations

    Quaternion Basics

    The orientation of any object can be described using various methods:

    1. Euler Angles: This method employs three angles around independent axes to express orientation.
    2. Orientation Direction Cosine Matrices: It utilizes a 3×3 matrix to represent a rotation.
    3. Quaternion: This method employs a 4D vector to represent orientation.

    Each of these methods has its own advantages and disadvantages. In this discussion, our primary focus is on Quaternions. When using quaternions to describe rotations, it offers several advantages compared to the other methods:

    • Clear Axis Representation: Quaternions make it very straightforward to identify the axis around which the rotation occurs.
    • Smooth Interpolation: Interpolating between two orientations is easy with quaternions. They do not suffer from issues like Gimbal Lock, which can be problematic in some other representations.

    However, the only drawback of the quaternion representation is that it may lack intuitiveness. In this system, a single entity expresses rotation. Compared to Euler Angles or Direction Cosine Matrices, this can be less immediately understandable.

    History

    William Rowan Hamilton developed quaternions in 1843. At that time, he was immersed in complex analysis as his primary area of interest. Complex analysis had not yet matured entirely, making his discovery a significant advancement. He found appeal in the notion that complex numbers could undergo rotations in a plane through multiplication with another complex number. Similarly, he harbored a keen interest in applying the same concept to vectors in three-dimensional space.

    Purely speaking mathematically, his contribution was in Field Extension of the complex field \(\mathbb{C}\) to 4 dimensional space of quaternions represented by \(\mathbb{H}\).” As this field is not Abelian, that is, it does not have the properties of being commutative, Hamilton received a lot of backlash. People considered studying such mathematical structures not very useful in those days. But in the current times it is no longer the case. A lot of non abelian groups like matrices are of very large importance.

    His contributions had a large impact on the mathematical community. As the American mathematician Howard Eves described the significance of Hamilton’s new approach by saying that

    it opened the floodgates of modern abstract algebra. By weakening or deleting various postulates of common algebra, or by replacing one of more of the postulates by others, which are consistent with the remaining postulates, an enormous variety of systems can be studied. As some of these systems we have groupoids, quasigroups, loops, semi-groups, monoids, groups, rings, integral domains, lattices, division rings, Boolean rings, Boolean algebras, fields, vector spaces, Jordan algebras, and Lie algebras, the last two being examples of non-associative algebras.

    — Howard Eves

    Quaternions also picked up interest in the computer science and graphics community due to its ease of representing rotations. In addition, Quaternions find applications in quantum physics, where they can represent spin states.

    Quaternion Operations

    Quaternions is an extension of the 2D complex numbers to 3d. Willain Rowan Hamilton invented it in1843. He was attempting to come up with a technique for multiplying triplets when he arrived at the quaternions. Just as two complex numbers in 2D easily represent rotations through multiplication, quaternions simplify the computation of rotations in 3D.

    Quaternions represent themselves as a vector of 4 elements in \(R^4\)

    $$
    \begin{bmatrix}
    a \\
    b \\
    c \\
    d \\
    \end{bmatrix} \epsilon R^4
    $$

    This also breaks down into scalar and vector parts

    a = scalar
    (b,c,d) = vector

    This is also represented as $$q =j\alpha_1 + i\alpha_2 + j\alpha_3 + k\alpha_4$$
    The Quaternions are governed by the following rules for multiplication

    $$
    i^2 = j^2 = k^2 = ijk = -1
    $$

    Addition

    Addition in quaternion is same like addition in the case of complex numbers where the numbers are added element wise.

    Two quaternions given by

    $$
    q_1 = a + b\hat{i} + c\hat{j} + d\hat{k}$$ and
    $$ q_2 = e + f\hat{i} + g\hat{j} + h\hat{k}$$

    gives a resultant sum

    $$
    q_1 + q_2 = (a + e) + (b + f)\hat{i} + (c+g)\hat{j} + (d+h)\hat{k}
    $$

    Multiplication

    The multiplication table is given as

     ijk
    i-1k-j
    j-k-1i
    kj-i-1

    Using these rules the two quaternions \(q_1\) and \(q_2\) given by

    $$
    q_1 = a + b\hat{i} + c\hat{j} + d\hat{k}$$ and
    $$ q_2 = e + f\hat{i} + g\hat{j} + h\hat{k}$$

    when mulplied using the distributive rule and applyting the multiplication table gives

    $$
    q_1 q_2 = (ae – bf – cg – dh) + \hat{i}(af + be + ch – dg) + \hat{j}(ag-bh+ce+df) + \hat{k}(ah+bg-cf+de)
    $$

    The other way of looking at this multiplication when viewed as scalar and vector combination is given as

    $$
    q_1 = (s_1, \vec{v_1})$$ and
    $$ q_2 = (s_2, \vec{v_2})$$

    where

    $$
    s1 = a, s2 = e, \vec{v_1} = (b,c,d), \vec{v2} = (f,g,h)
    $$

    hence the product is given as

    $$
    q_1q_2 = (s_1s_2 – \vec{v_1}.\vec{v2}, s_1\vec{v_2} + s_2\vec{v_1}+\vec{v_1}\times\vec{v_2})
    $$

    Conjugation

    Conjugation is the same as conjugation in the case of the complex numbers except that all the components are inverted in sign

    $$
    \overline{q_1} = a – b\hat{i} – c\hat{j} – d\hat{k}
    $$

    Magnitude

    Magnitude of a quaternion is given as the square root of sum of square of each element

    $$
    |{q}| = \sqrt{a^2 + b ^ 2 + c^2 +d^2}
    $$

    Inverse

    Inverse is given as conujugate divided by the square of the magnitude

    $$
    q^{-1}=\frac{\overline{q}}{|q|^2}
    $$

    Conclusion

    This post covered the history of the quaternion, the motivations around it. The quaternion basics sections also covers the basic quaternion operations. These will gear us to understand the applications of quaternion in the following post.

  • Simple Matar Paneer

    Simple Matar Paneer

    Time to Cook: 25 mins

    Ingredients

    Vegetables and others

    1. Paneer-200
    2. Onion- 3small
    3. Tomato- 2 big
    4. Peas-1/2cup (cooked or Frozen)
    5. Ginger-1inch
    6. Garlic-8cloves
    7. Cashew- 8pc (optional)

    Powder masala

    1. Red chilly powder-1 teaspoon
    2. Cumin-1teaspoon
    3. Coriander powder- 1 teaspoon
    4. Garam masala – 1/2 tsp
    5. Kasuri methi – 1teaspoon
    6. Ghee- 2Tablespoo
    7.  Coriander leave

    Steps to cook

    Sauté

    1. Add 1 tsp mustard oil in a pan and heat in medium flame till oil reached the smoking point
    2. Add ginger, garlic, cashew and onion in the pan and fry for 2 minutes in medium heat.
    3. Add chopped tomatoes to it and cook till tomatoes turn mushy
    4. Leave this out of the flame until it cools. Grind this to a paste.

    Cooking

    1. Add 2 table spoon ghee in a pan.
    2. Fry the ground paste in the pan for 5 minutes
    3. Add chilli powder – 1 teaspoon, coriander powder 1tsp, salt as per taste, cumin powder – 1tsp and fry for 2 mins.
    4. Add paneer and peas and cook it for 2 more mins.
    5. Add 1 cup water, cover it and leave it for 12 mins.
    6. Sprinkle and mix garam masala.
    7. Finally garnish with Kasuri methi and coriander leaves.

  • Configure Poetry Project for ML

    Configure Poetry, git & VS Code for jupyter notebooks

    The idea of this tutorial is to be able to set up python to start working with jupyter lab. From these setup I would like to be able to

    1. Create an virtual environment in python to manage my packages
    2. Version control my jupyter notebooks and other relevant files
    3. Configure VS code to run jupyter notebooks
    4. Finally deal with the annoying problem of Git and Jupyter. More about it later

    Configuring Poetry

    In this step we shall install poetry and install the necessary packages

    • Install python-poetry to get started with poetry
    • Create a new project using poetry new
    poetry new
    
    • Add the necessary packages using poetry
    poetry add jupyterlab
    poetry add scikit-learn
    poetry add matplotlib
    

    Configuring VS Code

    1. After installing vs code install the following plugins
      1. Python (ms-python)
      2. jupyter (ms-toolsai)

    [!important]
    The plugin installation might fail with latest builds like in Manjaro. Follow the procedure below

    Pasted image 20230429144038
    1. Press Ctrl + Shift + P, followed by Configure runtime arguments
    2. Add after a comma
    "enable-proposed-api": ["ms-toolsai.jupyter", "ms-python.python","ms-toolsai.jupyter-renderers"]
    

    Inorder to figure out these errors – Toggle developer tools in the command pallete. Go to console. It would print the errors which is a hint on what to do.

    Configure Git to avoid commiting every run of the same notebook as a change

    The problem

    Generally every run that the notebook goes through shows as a change. This happens as a lot of metadata about the run like the cell run count, time etc changes. This repeating changes makes it difficult to use GIt effectively. The code changes gets mixed with these run changes.

    Solutions

    1. The general approach to this problem would be to clean up the jupyter notebook before everycommit. The problem with this approach is that one has to remember to clean it. Also, if many files have undergone run then each file has to be manually cleaned up.
    2. Automatically clean the notebooks before commit is a better solution. This wouldn’t require people to remember to clean the files before every commit.

    The steps below help automating this step everytime the code is added to the staging area.

    • Initialize GIT in the folder using git init
    git init
    
    • Create a gitignore file to ignore all files except
      1. notebook files
      2. poetry lock and toml files
    • Create a .gitattribute file in source directory with the a single line _*
      .ipynb filter=strip-notebook-output_
      
    • Append the following at the end of the file .git/config
    [filter "strip-notebook-output"]
        clean = "jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR"
    

    Sample gitignore file

    *.*
    !.gitattributes
    !.gitignore
    !*.py
    !*.ipynb
    !*.md
    !poetry.lock
    !poetry.toml
    

    Sample gitattributes file

    .ipynb filter=strip-notebook-output_
    

    Sample .git/config file

    [core]
            repositoryformatversion = 0
            filemode = true
            bare = false
            logallrefupdates = true
    

    [gitflow “branch”]

    master = master develop = develop

    [gitflow “prefix”]

    feature = feature/ bugfix = bugfix/ release = release/ hotfix = hotfix/ support = support/ versiontag =

    [gitflow “path”]

    hooks = /home/bharad/Work/ML/.git/hooks

    [filter “strip-notebook-output”]

    clean = “jupyter nbconvert –ClearOutputPreprocessor.enabled=True –to=notebook –stdin –stdout –log-level=ERROR”

    [gitg]

    mainline = refs/heads/master