Uncategorized Archives - Mecany https://mecany.org/category/uncategorized/ Mon, 31 Jul 2023 01:44:14 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 https://i0.wp.com/mecany.org/wp-content/uploads/2021/12/cropped-mecany-512x512-1.png?fit=32%2C32&ssl=1 Uncategorized Archives - Mecany https://mecany.org/category/uncategorized/ 32 32 200460054 Listing sensors on any Android device https://mecany.org/lisiting-sensors-on-any-arduino-device/ Thu, 18 Jan 2018 14:07:11 +0000 https://mecany.org/?p=154 Today we can find a countless smartphones and mobile devices. When developing this can be a problem, because the hardware available in them, varies a lot. In Android there is a way to list the available sensors in a device, so based on this, we can check if the sensor we need is available or […]

The post Listing sensors on any Android device appeared first on Mecany.

]]>
Today we can find a countless smartphones and mobile devices.
When developing this can be a problem, because the hardware available in them, varies a lot.

In Android there is a way to list the available sensors in a device, so based on this, we can check if the sensor we need is available or create the necessary logic otherwise.

Para esto crearemos un nuevo proyecto, como blank o empty activity y dentro del MainActivity.java, colocaremos el siguiente código:
For this we will create a new project, as blank or empty activity and inside the MainActivity.java, we will place the following code:

package your.package.name.here;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import java.util.List;

public class MainActivity extends AppCompatActivity implements SensorEventListener {

    private SensorManager mSensorManager;
    private TextView sensor_list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        sensor_list = findViewById(R.id.sensor_list);

        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        List mList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
        sensor_list.setText("Sensors: ");

        for(int i=1; i

It is important to note that in this code a line must be replaced:
package your.package.name.here;
by the name of the package that we have chosen when creating the project.
On the other hand, the code refers to a TextView called sensor_list, this will be responsible for showing the available sensors, on the device screen.
This TextView is declared in the content_main.xml file



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:id="@+id/sensor_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.174"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.077" />
</android.support.constraint.ConstraintLayout>

The post Listing sensors on any Android device appeared first on Mecany.

]]> 24 Using Shift Register 74HC595 with Raspberry Pi https://mecany.org/using-shift-register-74hc595-with-raspberry-pi/ Thu, 04 Jan 2018 22:17:13 +0000 https://mecany.org/?p=28 In the previous article we were talking about this device and the advantages that we could have using it. But it may be a little difficult to understand without seeing an example or without understanding its operation and usage modes. Today we will be appling it using all the pins that this device provides us […]

The post Using Shift Register 74HC595 with Raspberry Pi appeared first on Mecany.

]]>
In the previous article we were talking about this device and the advantages that we could have using it. But it may be a little difficult to understand without seeing an example or without understanding its operation and usage modes.
Today we will be appling it using all the pins that this device provides us with a simple example using a code library open to everyone, made by Mecany and hosted on Github.

Requirements:

  • 1 Raspberry Pi
  • 1 Breadboard
  • 8 Leds
  • 8 Resistor 220 Ω
  • 17 Jumper Wires
  • 1 74HC595

Installing required library:

We can obtain a simple library to manage this shift registry from github:
In the same directory that you have the python script you need to do:

git clone git@github.com:marsminds/shiftr_74HC595.git

The procedure:

  • Before of connecting the Raspberry Pi to the power we need to build the circuit like the diagram is showing.

 

  • Connect the power in the Raspberry Pi
  • Save the code in a file called shift_register.py
import RPi.GPIO as GPIO
from shiftr_74HC595.shiftr_74HC595 import ShifRegister #importing the downloaded class
from time import sleep
GPIO.setmode(GPIO.BOARD)
data_pin = 7 #pin 14 on the 75HC595
latch_pin = 11 #pin 12 on the 75HC595
clock_pin = 12 #pin 11 on the 75HC595
shift_register = ShifRegister(data_pin, latch_pin, clock_pin) #using the class to manage the shift register
try:
    while 1:
        #setting the pins to turn on or off the leds
        shift_register.setOutput(0, GPIO.HIGH)
        shift_register.setOutput(1, GPIO.LOW)
        shift_register.setOutput(2, GPIO.LOW)
        shift_register.setOutput(3, GPIO.LOW)
        shift_register.setOutput(4, GPIO.HIGH)
        shift_register.setOutput(5, GPIO.LOW)
        shift_register.setOutput(6, GPIO.LOW)
        shift_register.setOutput(7, GPIO.HIGH)
        sleep(1)
        #setting the pins to turn on or off the leds
        shift_register.setOutput(0, GPIO.LOW)
        shift_register.setOutput(1, GPIO.HIGH)
        shift_register.setOutput(2, GPIO.HIGH)
        shift_register.setOutput(3, GPIO.HIGH)
        shift_register.setOutput(4, GPIO.LOW)
        shift_register.setOutput(5, GPIO.HIGH)
        shift_register.setOutput(6, GPIO.HIGH)
        shift_register.setOutput(7, GPIO.LOW)
        sleep(1)
except KeyboardInterrupt:
    print “Ctrl-C – quit”
GPIO.cleanup() #cleaning all the GPIO pins when the script is finished

 

  • Execute the file using the following command in the terminal:
sudo python shift_register.py

The post Using Shift Register 74HC595 with Raspberry Pi appeared first on Mecany.

]]>
19
Shift Register 74HC595 https://mecany.org/shift-register-74hc595/ Thu, 04 Jan 2018 21:04:31 +0000 https://mecany.org/?p=30 What is? A shift register is a sequential digital circuit, this means that the values ​​of their outputs depends on the values ​​of its inputs and previous values ​​of its inputs. It is a series of flip-flops connected in cascade which oscillate synchronously with the same clock signal. *flip-flops: is a multi-vibrator able to stay […]

The post Shift Register 74HC595 appeared first on Mecany.

]]>
What is?
A shift register is a sequential digital circuit, this means that the values ​​of their outputs depends on the values ​​of its inputs and previous values ​​of its inputs. It is a series of flip-flops connected in cascade which oscillate synchronously with the same clock signal.

*flip-flops: is a multi-vibrator able to stay in one of two possible states for an indefinite time into the absence of disturbances. This feature is highly used in digital electronics to store information.

Like all the integrated circuits, this has a data sheet. The data sheets give us all necessary information about the integrated circuit, such as: conditions to work, the inputs and outputs for each pin, the voltage input, temperature, etc.

In the data sheet we can find the Pin Config:

And the Pins Description:

Symbol Pin Description
Q1 1 parallel data output 1
Q2 2 parallel data output 2
Q3 3 parallel data output 3
Q4 4 parallel data output 4
Q5 5 parallel data output 5
Q6 6 parallel data output 6
Q7 7 parallel data output 7
GND 8 ground (0 V)
Q7′ 9 serial data output
MR 10 master reset (active LOW)
SHcp 11 shift register clock input
STcp 12 storage register clock input
OE 13 output enable input (active LOW)
DS 14 serial data input
Q0 15 parallel data output 0
Vcc 16 supply voltage

When I need one?
The shift register, if we work with Arduino or Raspberry Pi, can increase the number of pins to us. In this case the 74HC595 requires 3 input pins but returned 8 output pins.
This means that using only 3 pins on the Raspberry Pi or Arduino, we can manage until 8 pins. Very usefull when we are doing projects that requires more than the pines available in our Arduino or Raspberry Pi.

Example:

See what we can do in this example

The post Shift Register 74HC595 appeared first on Mecany.

]]>
20