Albert Palomas

Electronics & Life Lover

Category: Biography

Common bitwise operations in c/c++

This is a resume of most common bitwise operations in c/c++. Always useful to have in hand! Extracted from here: https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit

Setting a bit

number |= 1 << n;

Clearing a bit

number &= ~(1 << n);

Toggling a bit

number ^= 1 << n;

Checking a bit

bit = (number >> n) & 1;

Changing the nth bit to x

number = (number & ~(1 << n)) | (x << n);

Check file signature using windows built-in tool

Usually when you download a executable file from internet you want to verify its signature (MDx or SHx) to make sure it is the authentic file and not a hacked version.

Windows has a already built-in tool called CertUtil and you can call it from cmd:

CertUtil -hashfile <path to file> MD5

It will give back the MD5 checksum, but you can also check for any SHAx or MDx

LoRa – MySQL link using two Hope RFM69W and a Raspberry Pi

After looking for a already implemented solution for getting data from remote sensors, I decided to build my own solution, using existing components like Arduino, Raspberry Pi and especially I was interested on using the low cost RFM69W LoRa module.

My other target was to send the data to my own MySQL server instead of using third-party parterns like TTN.

And how it works? Basically it consist of two parts: sensors and gateway.

Sensor

It uses an Arduino Mini Pro 3.3V – 8MHz version as a processing core. It remains on deep-sleep mode, consuming less than 5 micro amperes and it wakes up every 10 minutes, sends data during few seconds, and sleep again. This strategy allows the sensor to be powered from 2 standard AA batteries and having an autonomy longer than a year.

Sensor powered from 2 AA batteries

The RFM69W module is connected to the Arduino using SPI and few control signals:

Arduino Mini PROLoRa RFM69W module
10 – SLAVE SELECTNNS
11 – MOSIMOSI
12 – MISOMISO
13 – SCKSCK
A0 – RESETRESET
2 – DIO0DIO0
7 – DIO1 (not used)DIO1
8 – DIO2 (not used)DIO2

It also contains a Adafruit Si7020 temerature & humidity sensor, connected via I2C to the Arduino (I removes and bridged transistors of this module to work at 3.3V)

Gateway

The gateway is mostly a Rasperry Pi connected to a RFM69 module using SPI and control signals This is the pinout:

Raspberry Pi (BCM numeration)LoRa RFM69 module
9 – MISOMISO
10 – MOSIMOSI
11 – SCKSCK
8NSS
25DIO0
22RESET
23EXTERNAL LED (not in module)

TODO: Write about software and firmware

idf.py build: too few arguments issue

Ok, if you got here, probably you got the same issue. After few hours trying to solve it, i finally found the solution.

The reason of this issue in my case is that I got a previous installation of python (platform.io has it’s own installer and I installed it before installing official esp-idf sdk).

The solution is to edit a pair of register keys, which are set from previous version of python and not updated by the new installation of python 2.7.14 in my case.

These are the keys you should edit (remember to make a backup before editing registers):

“HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command” and “HKEY_CLASSES_ROOT\Python.Files\shell\open\command ” Both sould have this same value: “C:\Python27\python.exe” “%1” %*

I hope you find it useful!


Paralleling power MOSFET considerations

mosfets in parallel

Are you thinking on paralleling power MOSFETs on your design to increase power output?
One much publicized benefit of power MOSFETs (compared to other semiconductor devices) is that it is easy to parallel them to create a group with increased capability.
Although this feature is superficially true, there are several potential problems that you should consider.
I recommend you to read these application notes from different manufacturers:

Good luck!

 

Burn prebuilt HEX or ELF file using MPLAB X

These are the simple but maybe unknown steps for burning a HEX file into a PIC microcontroller using MPLAB X IDE:

Select prebuilt project

Select prebuilt project

Select file and device

Select file and device

Write a project name

Write a project name

Make and load

Make and load

Ensure loading has succeeded

Ensure loading has succeeded

Scratch 4 Arduino with Adafruit Motor Shield v2

S4A is a powerful platform to learn programming Arduino but by default it can’t be interfaced with Adafruit Motor Shield. I have rewritten S4A firmware in order to achieve this goal.

You can download firmware from here.

I have tested it on Arduino UNO and this shield.

https://www.adafruit.com/products/1438

This is the relationship with S4A variables and Adafruit Motor Shield outputs:

S4A Adafruit Motor Shield
Analog 5 Speed DC Motor 1
Analog 6 Speed DC Motor 2
Digital 10 Direction DC Motor 1 (HIGH = FRONT) (LOW = BACKWARD)
Digital 11 Direction DC Motor 2 (HIGH = FRONT) (LOW = BACKWARD)
Digital 7 PWM Servomotor 1
Digital 8 PWM Servomotor 2

 

For compiling this firmware you will need Adafruit Motor Shield Library. It can be downloaded from Adafruit website:

https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-software

Programari lliure per a la fabricació substractiva

La intenció d’aquest post és fer una mica de resum de la meva experiència en programari lliure per fer servir amb eines i màquines de fabricació substractiva com freses i torns CNC, gravadores làser, plotters de dibuix i del tall… etc.

Programari de disseny (CAD):

Inkscape: Programa de disseny vectorial en 2D molt complert. Seria l’equivalent al Adobe Illustrator en el món Open Source. Pot exportar a DXF, SVG, EPS, HPGL i altres. Al ser un programa de disseny 2D es poden fer dissenys per fabricacions en 2D com: gravats làser, gravats amb fresa, plotters de marcatge, plotters de tall… El format més utilitzat per fer dibuixos en 2D és el DXF. Casi tots els programes CAM l’accepten. Cal tenir en compte que a vegades és necessari fer servir la opció Trayecto -> Objeto a Trayecto.

Gimp: Programa de dissey en 2D amb píxels molt complert. Seria l’equivalent al Adobe Photoshop. Pot exportar a JPG, PNG i altres. Una de les aplicacions per a la fabricació substractiva d’aquest programa és la generació de mapes de bits en escala de colors o B/N per fer fresats amb relleu. També hi ha programes CAM que detecten les línies de contorn per generar trajectòries de eina.

FreeCAD: Programa per al disseny de sòlids en 3D. Pot exportar a STL.

Google Sketchup + pluguin per exportar a STL:  Programa per al disseny de cossos en 3D. Programa que va començar sent de Google i ara és de Trimble. Molt intuïtiu per fer dissenys simples. Es necessita un pluguin per poder exportar a STL.

Programari per generar les trajectòries de la eina (CAM):

CamBam: Permet generar formes simples o importar models en 2D i generar les operacions de: Gravat, Pocketing, Perfil. Actualment la versió lliure no permet treballar amb models 3D però la versió de pagament (molt barata en comparació amb altres softwares CAM) permet importar models 3D i generar les trajectòries de fresat en 3D. Permet generar el GCODE amb el postprocessador seleccionat. Les eines i el postprocessador es poden triar desde la pestanya “System”.

Programari de simulació:

CAMOtics: Permet obrir un fitxer G-Code i dibuixar-ne la trajectòria tenint en compte el gruix de la eina. Es pot exportar el model simulat en STL.

GrblGRU: Simulació de la màquina sencera.

Programari de comunicació amb la màquina (Grbl)

Grbl és un intèrpret de comandes GCode que normalment s’instal·la sobre un Arduino i aquest controla la màquina amb motors PAP o Servomotors. Aquests programes es comuniquen amb el Arduino per port sèrie sobre USB. Tots són similars però amb petites diferències que en funció de la nostra màquina i els treballs que volguem fer, en podem fer servir un o un altre. En general, en tots es pot controlar la màquina manualment i es pot enviar un fitxer G-Code.

Universal G Code Sender

GCode Teleporter

Grbl Controller

GCodeSender

© 2025 Albert Palomas

Theme by Anders NorenUp ↑