25 Oct 2019

How to measure current with voltmeter only or multimeter without current measurement

Make a simple shunt and measure voltage drop on the shunt resistor.

to the circuit <---- < Shunt 2,4R or any low value resistor > ----> to the circuit 
*for better accuracy check the value of shunt if you can.

Calculate via Ohm's law:

I, A = Udrop, V / 2,4 R

Bingo!

24 Oct 2019

Arduino "Fireflies" Lamp with Light Detector & Sleep Mode

Arduino "Fireflies" Lamp with Light Detector & Sleep Mode

Board: 
Robotdyn Arduino Pro Mini 3.3V, 8MHz
(Attention! The wrong pinout by the manufacturer in the *pdf doc, use UNO's labels! pin 11 is PWM, not 12!)
 
Connection:
GND |-----< 9k1 >----- (A3) ------< LDR >-----> VCC 3.3V
GND |-----< cathode LED anode >-----< 240R >-----> to PWM pin (3, 5, 6, 9, 10, 11)

Energy-saving:
- Remove Power LED from the board
- Remove DC regulator


Arduino "Fireflies" Lamp with Light Detector & Sleep Mode

25 Sept 2019

How to add Entity Framework Core into ASP.Net Core project

Installation

1. Open a terminal and navigate into the project's folder
2. Use the following .NET Core CLI command from the operating system's command line to install or update the EF Core SQL Server provider

Global EF installation

dotnet ef must be installed as a global or local tool. Most developers will install dotnet ef as a global tool with the following command:

dotnet tool install --global dotnet-ef

https://docs.microsoft.com/en-us/ef/core/get-started/?tabs=netcore-cli

=============

Project

for MS SQL
dotnet add package Microsoft.EntityFrameworkCore.SqlServer

or for SQLite
dotnet add package Microsoft.EntityFrameworkCore.Sqlite 

modifier
-v // version
-v 2.2.0

3. Install tools to carry out EF Core-related tasks in your project, like creating and applying database migrations, or creating an EF Core model based on an existing database

dotnet add package Microsoft.EntityFrameworkCore.Design

For ASP.NET Core apps, this package is included automatically. Database provider design-time packages such as Microsoft.EntityFrameworkCore.SqlServer.Design are no longer required or supported from EF Core 2.0 and later, but aren't automatically removed when upgrading the other packages

4. To get the Package Manager Console tools for EF Core, install

dotnet add package Microsoft.EntityFrameworkCore.Tools


or install packages via NuGet

=============

Add Migrations

After you've defined your initial model, it's time to create the database. To add an initial migration, run the following command:

dotnet ef migrations add InitialCreate 

Update the database
Next, apply the migration to the database to create the schema.

dotnet ef database update

Remove a migration
Sometimes you add a migration and realize you need to make additional changes to your EF Core model before applying it. To remove the last migration, use this command. After removing the migration, you can make the additional model changes and add it again.

dotnet ef migrations remove

Revert a migration
If you already applied a migration (or several migrations) to the database but need to revert it, you can use the same command to apply migrations, but specify the name of the migration you want to roll back to.

dotnet ef database update LastGoodMigration

=============

Commands

dotnet ef migrations add
dotnet ef migrations list
dotnet ef migrations script
dotnet ef dbcontext info
dotnet ef dbcontext scaffold
dotnet ef database drop
dotnet ef database update


24 Sept 2019

Getting started ASP.NET Core (Web API Project)

1. Install .NET Core SDK

2. Test
dotnet --version

3. Create project from a template
dotnet new webapi -o myApp

or

dotnet new webapp -o myWebApp --no-https

The -o parameter creates a directory named myApp where app is stored

4. Navigate into the project's folder and run
dotnet run

Additional

Run the following commands to install the required packages

dotnet restore

How to use Visual Studio Code to manage MSSQL Databases

1. Install the mssql extension for VS Code
2. Create or open a SQL file
3. Connect to SQL Server
-- Press Ctrl+Shift+P or F1 to open the Command Palette.
-- Start to type MS SQL and select MS SQL: Connect from the dropdown
--- MS SQL: Manage Connection Profiles
--- Then select Create
--- Follow the prompts to specify the properties for the new connection profile. After specifying each value, press Enter to continue.

5. Run the SQL script to test it.

CREATE DATABASE AppDB
GO

EXEC SP_HELPDB AppDB;

USE AppDB;

CREATE TABLE [User]
(
UserId int NOT NULL PRIMARY KEY IDENTITY,
FirstName [NVARCHAR](50) NOT NULL,
LastName [NVARCHAR](50) NOT NULL
);
GO

INSERT INTO [User]
(FirstName, LastName)
VALUES
('Borys', 'Razin'),
('Olga', 'Proshkina'),
('Ivan', 'Yankovsky');
GO

SELECT * FROM [User];

4. Press Ctrl+Shift+E to execute the Transact-SQL commands.

More info here

How to run MS SQL Server on macOS using Docker.


Pull the SQL Server 2017 Linux container image from Microsoft Container Registry.

sudo docker pull microsoft/mssql-server-linux


Run the container image with Docker

docker run -d --name mssqllinux -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourPassword123' -p 1433:1433 microsoft/mssql-server-linux


To view your Docker active containers (container is an instance of the image)

sudo docker ps -a 


-a // active containers

docker container ls


To view your docker images

docker image ls


Remove image

docker rmi -f <image_id>

-f // force


Remove container (you should stop the container before)

docker stop <id_or_name>
docker rm <id_or_name>



Start container after reboot

docker start <id_or_name>

========================


Test connection with sql-cli

Install sql-cli (Node.js should be installed)

sudo npm install -g sql-cli

Connect

mssql -u sa -p YourPassword123

after connection test with the command

select @@version


Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64) 
Nov 30 2018 12:57:58 
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)

========================

Connect to Database:

Login: sa
Password: YourPassword123
Server: localhost


7 Sept 2019

Getting started React JS. How to deploy React App to Heroku Host.

React JS Start

sudo npm install -g create-react-app

cd react-projects-folder
create-react-app my-app-name

cd my-app-name
npm start

How to deploy React App to Heroku Host.

git init
heroku create $APP_NAME --buildpack mars/create-react-app

// where the $APP_NAME could be like "poshta-app", then it will be used for the domain name: https://poshta-app.herokuapp.com/ 

git add .
git commit -m "Start with create-react-app"
git push heroku master
heroku open

5 Sept 2019

Using Visual Studio Code for AVR (macOS)

Setup IntelliSense

1. Open a project's folder as Workspace in VS Code.
2. Install C/C++ Extension
3. Create a folder .vscode in the project's folder.
4. Place a file c_cpp_properties.json in the .vscode folder

Check documentation here or try the example project.

{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/local/include",
"/usr/bin/gcc",
"/Users/usernamefolder/Library/avr-toolchain/avr/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "${default}",
"browse": {
"path": [
"/usr/local/include",
"/usr/bin/gcc",
"/Users/usernamefolder/Library/avr-toolchain/avr/include",
"${workspaceRoot}"
]
},
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}"
}
],
"version": 4
}

1 Sept 2019

Make Utility for AVR. (AVR build automation)

The Make Utility is a build tool that automatically determines which source files of a program need to be recompiled and/or linked. We can compile, link and flashing of AVR microcontroller using only one command in the terminal: make. Make remains widely used, especially in Unix-like operating systems.

How to use

1. Create a file inside of project's folder without extension and called Makefile.
2. Place commands in it.
3. Open a terminal and move into the project's folder with Makefile.
4. Type make command in terminal.
5. Use labels like: 
make all
make flash
make clean

Check here the example for ATTiny13

=====

MCU=attiny13
F_CPU=1200000
CC=avr-gcc
CS=avr-size
OBJCOPY=avr-objcopy
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
SRCS=main.c

all:
@printf "\n"
@printf " ===> Compiling: \n"
${CC} ${CFLAGS} -o ${TARGET}.bin ${SRCS}
@printf "\n"
@printf " ===> Size: \n"
${CS} -C ${TARGET}.bin
@printf " ===> Generating .HEX: \n"
${OBJCOPY} -j .text -j .data -O ihex ${TARGET}.bin ${TARGET}.hex

flash:
@printf "\n"
@printf " ===> Flashing: \n"
avrdude -p ${MCU} -B 4 -c usbasp -U flash:w:${TARGET}.hex:i -F -P usb

clean:
@printf "\n"
@printf " ===> Cleaning: \n"
rm -f *.bin *.hex


31 Aug 2019

How to setup AVR programming environment on macOS. Step-by-step guide

This is a lightweight and easy to setup AVR dev programming instruction where we will use AVR 8-bit Toolchain 3.6.2 - Mac OS X 64-bit and will not use the old CrossPack. By the way, GNU Toolchain Documentation is here.


Let's start!
----------------->

AVR Toolchain Installation (Compiler, Assembler, Linker, Librarian, C Library, etc)


1. Download sh script from here
2. Run it. sudo sh <path>/install_toolchain.sh

1. Download sh script from here
2. Run it. sudo sh <path>/avr_toolchain_install.sh
3. Reboot your machine and test it using the terminal command avr-gcc -v 

You should get the answer: gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_503)

AVR Programmer Installation (Avrdude)


Before this we need to install libusb, you can get it here (I use libusb-1.0.23.tar.bz2)
Unzip, navigate, install:
1. sudo ./configure
2. sudo make
3. sudo make install

then move through these steps:

1. Download the current release of avrdude here (I use avrdude-6.3)
2. Unzip the downloaded file. In a Terminal window, navigate to the avrdude directory: cd <path>/avrdude-6.3
3. Configure avrdude. type: sudo ./configure
4. Compile avrdude. type: sudo make
5. Install avrdude. type: sudo make install
6. Test it by feeding the terminal with  avrdude -version

You should get the answer: avrdude version 6.3


Thanks to all of avr funs we have done with the software part!

Compiling an Example (for the cutiest ATTiny13 chip)


1. Get the example here
2. Navigate to the example directory cd <path>/example
3. Compile the code: avr-gcc -Wall -g -Os -mmcu=attiny13 -o main.bin main.c
4. Check program and data memory size: avr-size -C main.bin
5. Generate a HEX file for a programmer: avr-objcopy -j .text -j .data -O ihex main.bin main.hex



Time to flash the chip!

Flashing the chip


1. Connect USBasp programmer (You don't need a driver on macOS)
2. Move into the project's directory
3. Open terminal and type: avrdude -p attiny13 -c usbasp -U flash:w:main.hex:i

You should get the answer: avrdude: error: program enable: target doesn't answer. 1 
That means we are ready to connect real MCU and try again



How to setup AVR programming environment on macOS.

Troubleshooting

1. ----------------------------------------
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.


Solution -> Use slow programming speed by adding flag B 1 - B 400 like this:
avrdude -p attiny13 -B 4 -c usbasp -U flash:w:main.hex:i


Files

Adafruit avrdude documentation is here.
All files are here

30 Jun 2019

How to Set or Clear bits in Microcontrollers


Let’s say you have a variable x.
  • int x = 0b10100110;
Then in order to set the nth bit of x (counting from righthand side) to 1. You can write as follows:
  • int y = x | (1 << n);
If you want to set the nth bit of x to 0, you can do it like this:
  • int y = x & ~(1 << n);
If you want to flip the nth bit of x, you can write like this:
  • int y = x ^ (1 << n)

You can easily turn these into macros.
  • #define SETBIT(num,bitpos) (num|(1<<bitpos))
  • #define CLRBIT(num,bitpos) (num&(~(1<<bitpos)))

Popular Posts