Skip to content

Instantly share code, notes, and snippets.

@charlie2951
charlie2951 / main.cpp
Created June 27, 2022 18:37
Number gesture detection main C++ source file
#include <stdio.h>
#include <Numer_detection_inferencing.h>
#include "ei_classifier_porting.h"
#include "pico/stdlib.h"
#include "ei_run_classifier.h"
#include "hardware/gpio.h"
#include "hardware/adc.h"
/* Private variables ------------------------------------------------------- */
import array
import micropython
import utime
from machine import Pin
from micropython import const
class InvalidChecksum(Exception):
pass
class InvalidPulseCount(Exception):
#Python program to read temp and humidity data from serial port
#and to send them to a webpage
#DHT11 sensor is used
#Version 1.0.4
import serial
import time
file_name = "index.html"
ser = serial.Serial('COM5', 112500, timeout=1)
print("Reading data from serial port.....");
#Python script to read serial port data and send them to UBIDOTS cloud
import time
import requests
import math
import random
import serial
TOKEN = "BBFF-ofWonfD405MScpxOFPtRVbQkhVSscz" # Put your TOKEN here
DEVICE_LABEL = "My_PC" # Put your device label here
VARIABLE_LABEL_1 = "temperature" # Put your first variable label here
VARIABLE_LABEL_2 = "humidity" # Put your second variable label here
##Micropython implementation of Multi-layer Perceptron (MLP)
##Artificial Neural network-Fully connected Dense layer
##Trained hyperparameters are collected from tensorflow-keras
# and fed to our Neural network for testing and prediction
##Version:1.0.1
##Date 14/06/2022
def zeros1d(x): # 1d zero matrix
z = [0 for i in range(len(x))]
return z
import tensorflow as tf
from tensorflow import keras
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
pima = pd.read_csv("diabetes.csv")
pima.head()
#split dataset in features and target variable
feature_cols = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness','Insulin','BMI','DiabetesPedigreeFunction', 'Age']
Xraw = pima[feature_cols] # Features
from pylab import logistic_regression as lm
def csvread(file_name): # function for reading csv file
f = open(file_name, 'r')
w = []
tmp = []
for each in f:
w.append(each)
# print (each)
# print(w)
import pandas as pd
col_names = ['pregnant', 'glucose', 'bp', 'skin', 'insulin', 'bmi', 'pedigree', 'age', 'label']
# load dataset
pima = pd.read_csv("diabetes.csv")
pima.head()
#split dataset in features and target variable
feature_cols = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness','Insulin','BMI','DiabetesPedigreeFunction', 'Age']
Xraw = pima[feature_cols] # Features
##Logistic Regression in Raspberry Pi Pico-RP-2040 using Micropython
##Use small file size to avoid memory error
##Tested using only 100 row in the diabetes.csv file, check file name, make sure
#that 1st row (column header of csv file) is removed (string not supported)
from pylab import logistic_regression as lm
def csvread(file_name): # function for reading csv file
f = open(file_name, 'r')
w = []
tmp = []
for each in f:
@charlie2951
charlie2951 / logistic_regression.py
Created June 19, 2022 09:46
Functions for logistic regression classifier
# scratch code for logistic regression in Micropython
# Numpy-like matrix library from scratch
# Created on 7/6/2022
# Note that, matrix must be two-dimensional
#Rev01: 7/6/22
#Rev02:11/6/22
def zeros(rows, cols):
"""
Creates a matrix filled with zeros.
:param rows: the number of rows the matrix should have