Blog Image

guivi

About the blog

In this blog I will keep track of projects I develop though out this year and may be in the future. For now it is juts a testing ground for developing the blog itself but I hope as I put more material it will become a good place for me to hold information.

AI Annotation Software

Artificial Intelligence Posted on 28 Dec, 2022 21:26:18

This a collection of links to YouTube videos describing software for annotating data to be used in AI supervised learning.



GStreamer command to stream ip over TCP or UDP

Gstreamer Posted on 25 Oct, 2022 19:41:49
• gst-launch-1.0 rtspsrc location="rtsp:///user=admin_password=tlJwpbo6_channel=1_stream=0.sdp?real_stream" protocols="udp" ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! autovideosink
• gst-launch-1.0 rtspsrc location="rtsp:///user=admin_password=tlJwpbo6_channel=1_stream=0.sdp?real_stream" protocols="tcp" ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! autovideosink


omxplayer to stream

Pi Stuff Posted on 26 Sep, 2022 15:51:59

omxplayer “rstp://user:pass@host:port/path/subpath” –avdict rtsp_transport:tcp –no-osd –live –with-info –stats;



Humidity & Temperature

Arduino Posted on 28 Jul, 2022 08:25:01
#include <OneWire.h>
#include <DallasTemperature.h>
#include <stdio.h>

const uint8_t ID = 1;// Identification number for the unit.

// Data wire is plugged into digital pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);  
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);

// Calculate checksum of the messsage
uint16_t Fletcher16( uint8_t *data, int count )
{
   uint16_t sum1 = 0;
   uint16_t sum2 = 0;
   int index;

   for ( index = 0; index < count; ++index )
   {
      sum1 = (sum1 + data[index]) % 255;
      sum2 = (sum2 + sum1) % 255;
   }
   return (sum2 << 8) | sum1;
}

// Function where to initialize things.
void setup() {
   sensors.begin();  // Start up the dallas library
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
    uint8_t incomingByte = Serial.read();
    if (incomingByte - 48 == ID){
      // put your main code here, to run repeatedly:
      int hum = analogRead(A0);
      float temp = sensors.getTempCByIndex(0);
      char buffer1[256], buffer2[256];
      sprintf(buffer1, "$%d,%d,%d", ID, hum, (int)(temp*10));
      uint16_t sum = Fletcher16(buffer1, strlen(buffer1));
      sprintf(buffer2,"%s*%02X\n", buffer1, sum); 
      Serial.print(buffer2);
    }
  }
  delay(10);
}


Adding Board 2 Arduino

Arduino Posted on 28 Jul, 2022 07:57:33

To add the boards fro the links in this page, the link has to be placed under File->Preferences->Additional Board Manager URL:
Then the board can be added through
tools->board->Board Manager.

For the LGT8F family boards:
https://raw.githubusercontent.com/dbuezas/lgt8fx/master/package_lgt8fx_index.json

Adafruit compatible bords:
https://adafruit.github.io/arduino-board-index/package_adafruit_index.jsonhttps://adafruit.github.io/arduino-board-index/package_adafruit_index.json



Using ISO with Ventoy

Education, Linux, things Posted on 28 Jul, 2022 07:47:46

Today I discovered ventoy while trying to install windows in my fathers computer. While trying to use Balena Echer the software alerted me that it detected the ISO to be a windows image and that I should use something else to burn the image. Because of that I discovered Ventoy (https://www.ventoy.netbern/en/doc_linux_webui.html)
On the webpage there is a description on how to use it in Linux.
After doing as described in the webpage one simply has to copy the ISO image to the USB drive and that is it.

Description as in the webpage

1. run sudo sh VentoyWeb.sh in the terminal
2. open browser and visit http://127.0.0.1:24680

Tip: Step 1 will print the http address in the terminal. In many distros you can just press Ctrl and click the link with your mouse meanwhile.

By default, VentoyWeb.sh listen on 127.0.0.1:24680, and you can only visit it on the localhost.
You can also specify the IP and port like this sudo sh VentoyWeb.sh -H 192.168.0.100 -P 8080
Then you can visit the WebUI from another computer. This is very convenient in some cases.
For example, you have a computer with Linux in it, but it doesn’t have a GUI environment. You can run the script as above, and visit the WebUI from another computer (e.g. Windows) as long as they are connected on the internet.



fridge

Arduino, C/C++ Programming Posted on 19 Jul, 2022 22:01:48
//----------------------Screen Bits
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void InitDisp(void)
{
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  // display.display();
  // delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();
}

void DisplayTemp(float cel)
{
  display.clearDisplay();

  display.setTextSize(2);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.setCursor(0, 0);     // Start at top-left corner
  display.cp437(true);         // Use full 256 char 'Code Page 437' font

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  char buf[256];
  int integerPart = (int)cel;
  int decimalPart = ((int)(cel*100)%100);
  sprintf(buf, "Temp:%d.%d", (int)cel, decimalPart);
  for(int16_t i=0; i<strlen(buf); i++) {
    display.write(buf[i]);        
  }

  display.display();
}
//---------------------------------------------------------------------
//---------------------- Temperature Sensor
#include <OneWire.h>
OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)
byte g_addr[8];
byte g_type_s;
void InitTemp(void)
{
  if ( !ds.search(g_addr)) {
    Serial.println("No addresse.");
    Serial.println();
    ds.reset_search();
    delay(250);
    while(true){};
  }

  Serial.print("ROM =");
  for(int i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(g_addr[i], HEX);
  }

  if (OneWire::crc8(g_addr, 7) != g_addr[7]) {
      Serial.println("CRC is not valid!");
      while(true){};
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (g_addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      g_type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      g_type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      g_type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 
}
//----------------------------------------------------------------------
//--------------------- Digital pins
const char SW1 = 2;

//---------------------- PROGRAM
void setup(void) {
  Serial.begin(9600);

  pinMode( SW1, OUTPUT);
  digitalWrite(SW1, LOW);

  InitTemp();
  InitDisp();
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  
  float celsius, fahrenheit;
  
  ds.reset();
  ds.select(g_addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(g_addr);    
  ds.write(0xBE);         // Read Scratchpad

  /*
  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  */
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    /*
    Serial.print(data[i], HEX);
    Serial.print(" ");
    */
  }
  /*
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();
  */
  
  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (g_type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");

  // Do something with the temperature.
  if (celsius <= 21)
    digitalWrite(SW1, LOW);
  else if (celsius > 21)
    digitalWrite(SW1, HIGH);

  // Display temperature
  DisplayTemp(celsius);
  
}


Wild_Thumper_Control

Arduino Posted on 30 Jun, 2022 07:26:44
/*

v1.0 RoboSavvy 16/11/2010
Added code to prevent drain of LiPo Batteries.

*/
#include <Servo.h>
#include "IOpins.h"
#include "Constants.h"
//#include <LCD4Bit_mod.h> 
//create object to control an LCD.  
//number of lines in display=1
//LCD4Bit_mod lcd = LCD4Bit_mod(2); 

//-------------------------------------------------------------- define global variables --------------------------------------------

unsigned int Volts;
unsigned int LeftAmps;
unsigned int RightAmps;
unsigned long chargeTimer;
unsigned long leftoverload;
unsigned long rightoverload;
int highVolts;
int startVolts;
int Leftspeed=0;
int Rightspeed=0;
int Speed;
int Steer;
byte Charged=1;                                               // 0=Flat battery  1=Charged battery
int Leftmode=1;                                               // 0=reverse, 1=brake, 2=forward
int Rightmode=1;                                              // 0=reverse, 1=brake, 2=forward
byte Leftmodechange=0;                                        // Left input must be 1500 before brake or reverse can occur
byte Rightmodechange=0;                                       // Right input must be 1500 before brake or reverse can occur
int LeftPWM;                                                  // PWM value for left  motor speed / brake
int RightPWM;                                                 // PWM value for right motor speed / brake
int data;
int servo[7];
boolean isDebug=true;
//-------------------------------------------------------------- define servos ------------------------------------------------------


Servo Servo0;                                                 // define servos
Servo Servo1;                                                 // define servos
Servo Servo2;                                                 // define servos
Servo Servo3;                                                 // define servos
Servo Servo4;                                                 // define servos
Servo Servo5;                                                 // define servos
Servo Servo6;                                                 // define servos

void setup()
{
  //------------------------------------------------------------ Initialize Servos ----------------------------------------------------

  Servo0.attach(S0);                                          // attach servo to I/O pin
  Servo1.attach(S1);                                          // attach servo to I/O pin
  Servo2.attach(S2);                                          // attach servo to I/O pin
  Servo3.attach(S3);                                          // attach servo to I/O pin
  Servo4.attach(S4);                                          // attach servo to I/O pin
  Servo5.attach(S5);                                          // attach servo to I/O pin
  Servo6.attach(S6);                                          // attach servo to I/O pin

  //------------------------------------------------------------ Set servos to default position ---------------------------------------

  Servo0.writeMicroseconds(DServo0);                          // set servo to default position
  Servo1.writeMicroseconds(DServo1);                          // set servo to default position
  Servo2.writeMicroseconds(DServo2);                          // set servo to default position
  Servo3.writeMicroseconds(DServo3);                          // set servo to default position
  Servo4.writeMicroseconds(DServo4);                          // set servo to default position
  Servo5.writeMicroseconds(DServo5);                          // set servo to default position
  Servo6.writeMicroseconds(DServo6);                          // set servo to default position

  //------------------------------------------------------------ Initialize I/O pins --------------------------------------------------

  pinMode (Charger,OUTPUT);                                   // change Charger pin to output
  digitalWrite (Charger,1);                                   // disable current regulator to charge battery

  if (Cmode==1) 
  {
    Serial.begin(Brate);                                      // enable serial communications if Cmode=1
    Serial.println("Started");
    Serial.flush();                                           // flush buffer
  } 
  //Serial.begin(57600);
  
  //Initialize the LCD debug screen
  //lcd.init();
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
  //lcd.clear();
  //lcd.printIn("KEYPAD testing... pressing");
}


void loop()
{
  //------------------------------------------------------------ Check battery voltage and current draw of motors ---------------------

  Volts=analogRead(Battery);                                  // read the battery voltage
  LeftAmps=analogRead(LmotorC);                               // read left motor current draw
  RightAmps=analogRead(RmotorC);                              // read right motor current draw

/*
  if (LeftAmps>Leftmaxamps)                                   // is motor current draw exceeding safe limit
  {
    analogWrite (LmotorA,0);                                  // turn off motors
    analogWrite (LmotorB,0);                                  // turn off motors
    leftoverload=millis();                                    // record time of overload
  }

  if (RightAmps>Rightmaxamps)                                 // is motor current draw exceeding safe limit
  {
    analogWrite (RmotorA,0);                                  // turn off motors
    analogWrite (RmotorB,0);                                  // turn off motors
    rightoverload=millis();                                   // record time of overload
  }
*/
  
  if ((Volts<lowvolt) && (Charged==1))                        // check condition of the battery
  {                                                           // change battery status from charged to flat

    //---------------------------------------------------------- FLAT BATTERY speed controller shuts down until battery is recharged ----
    //---------------------------------------------------------- This is a safety feature to prevent malfunction at low voltages!! ------

    Charged=0;                                                // battery is flat
    highVolts=Volts;                                          // record the voltage
    startVolts=Volts;
    chargeTimer=millis();                                     // record the time
	
	if(lipoBatt==0)											  // checks if LiPo is being used, if not enable the charge circuit
	{
		digitalWrite (Charger,0);                                 // enable current regulator to charge battery
	}
  }

  //------------------------------------------------------------ CHARGE BATTERY -------------------------------------------------------

  if ((Charged==0) && (Volts-startVolts>67) && (lipoBatt == 0)) // if battery is flat and charger has been connected (voltage has increased by at least 1V) and there is no LiPo
  {
    if (Volts>highVolts)                                      // has battery voltage increased?
    {
      highVolts=Volts;                                        // record the highest voltage. Used to detect peak charging.
      chargeTimer=millis();                                   // when voltage increases record the time
    }

    if (Volts>batvolt)                                        // battery voltage must be higher than this before peak charging can occur.
    {
      if ((highVolts-Volts)>5 || (millis()-chargeTimer)>chargetimeout) // has voltage begun to drop or levelled out?
      {
        Charged=1;                                            // battery voltage has peaked
        digitalWrite (Charger,1);                             // turn off current regulator
      }
    } 
  }

  else

  {//----------------------------------------------------------- GOOD BATTERY speed controller opperates normally ----------------------

    switch(Cmode)
    {
    case 0:                                                   // RC mode via D0 and D1
      RCmode();
      break;

    case 1:                                                   // Serial mode via D0(RX) and D1(TX)
      SCmode();
      break;

    case 2:                                                   // I2C mode via A4(SDA) and A5(SCL)
      I2Cmode();
      break;
    }

    // --------------------------------------------------------- Code to drive dual "H" bridges --------------------------------------

    if (/*Charged==*/1)                                           // Only power motors if battery voltage is good
    {
      if ((millis()-leftoverload)>overloadtime)             
      {
        switch (Leftmode)                                     // if left motor has not overloaded recently
        {
        case 2:                                               // left motor forward
          analogWrite(LmotorA,0);
          analogWrite(LmotorB,LeftPWM);
          break;

        case 1:                                               // left motor brake
          analogWrite(LmotorA,LeftPWM);
          analogWrite(LmotorB,LeftPWM);
          break;

        case 0:                                               // left motor reverse
          analogWrite(LmotorA,LeftPWM);
          analogWrite(LmotorB,0);
          break;
        }
      }
      if ((millis()-rightoverload)>overloadtime)
      {
        switch (Rightmode)                                    // if right motor has not overloaded recently
        {
        case 2:                                               // right motor forward
          analogWrite(RmotorA,0);
          analogWrite(RmotorB,RightPWM);
          break;

        case 1:                                               // right motor brake
          analogWrite(RmotorA,RightPWM);
          analogWrite(RmotorB,RightPWM);
          break;

        case 0:                                               // right motor reverse
          analogWrite(RmotorA,RightPWM);
          analogWrite(RmotorB,0);
          break;
        }
      } 
    }
    else                                                      // Battery is flat
    {
      analogWrite (LmotorA,0);                                // turn off motors
      analogWrite (LmotorB,0);                                // turn off motors
      analogWrite (RmotorA,0);                                // turn off motors
      analogWrite (RmotorB,0);                                // turn off motors
    }
  }
}


void RCmode()
{
  //------------------------------------------------------------ Code for RC inputs ---------------------------------------------------------

  Speed=pulseIn(RCleft,HIGH,25000);                           // read throttle/left stick
  Steer=pulseIn(RCright,HIGH,25000);                          // read steering/right stick


  if (Speed==0) Speed=1500;                                   // if pulseIn times out (25mS) then set speed to stop
  if (Steer==0) Steer=1500;                                   // if pulseIn times out (25mS) then set steer to centre

  if (abs(Speed-1500)<RCdeadband) Speed=1500;                 // if Speed input is within deadband set to 1500 (1500uS=center position for most servos)
  if (abs(Steer-1500)<RCdeadband) Steer=1500;                 // if Steer input is within deadband set to 1500 (1500uS=center position for most servos)

  if (Mix==1)                                                 // Mixes speed and steering signals
  {
    Steer=Steer-1500;
    Leftspeed=Speed-Steer;
    Rightspeed=Speed+Steer;
  }
  else                                                        // Individual stick control
  {
    Leftspeed=Speed;
    Rightspeed=Steer;
  }
  /*
  Serial.print("Left:");
  Serial.print(Leftspeed);
  Serial.print(" -- Right:");
  Serial.println(Rightspeed);
  */
  Leftmode=2;
  Rightmode=2;
  if (Leftspeed>(Leftcenter+RCdeadband)) Leftmode=0;          // if left input is forward then set left mode to forward
  if (Rightspeed>(Rightcenter+RCdeadband)) Rightmode=0;       // if right input is forward then set right mode to forward

  LeftPWM=abs(Leftspeed-Leftcenter)*10/scale;                 // scale 1000-2000uS to 0-255
  LeftPWM=min(LeftPWM,255);                                   // set maximum limit 255

  RightPWM=abs(Rightspeed-Rightcenter)*10/scale;              // scale 1000-2000uS to 0-255
  RightPWM=min(RightPWM,255);                                 // set maximum limit 255
}







void SCmode()
{// ------------------------------------------------------------ Code for Serial Communications --------------------------------------

                                                              // FL = flush serial buffer
 
                                                              // AN = report Analog inputs 1-5
                                                              
                                                              // SV = next 7 integers will be position information for servos 0-6
 
                                                              // HB = "H" bridge data - next 4 bytes will be:
                                                              //      left  motor mode 0-2
                                                              //      left  motor PWM  0-255
                                                              //      right motor mode 0-2
                                                              //      right motor PWM  0-255
   
 
  if (Serial.available()>1)                                   // command available
  {
    int A=Serial.read();
    int B=Serial.read();
    int command=A*256+B;
    switch (command)
    {
      case 17996:                                             // FL
        Serial.flush();                                       // flush buffer
        break;
        
      case 16718:               // AN - return values of analog inputs 1-5
        for (int i=1;i<6;i++)          // index analog inputs 1-5
        {
          data=analogRead(i);     // read 10bit analog input 
          Serial.write(highByte(data));     // transmit high byte
          Serial.write(lowByte(data));    // transmit low byte
        }
        break;
              
       case 21334:// SV - receive postion information for servos 0-6
         for (int i=0;i<15;i++)     // read 14 bytes of data
         {
           Serialread();                                      
           servo[i]=data;
         }

         Servo0.writeMicroseconds(servo[0]*256+servo[1]);     
         Servo1.writeMicroseconds(servo[2]*256+servo[3]);     // set servo position
         Servo2.writeMicroseconds(servo[4]*256+servo[5]);     // set servo position
         Servo3.writeMicroseconds(servo[6]*256+servo[7]);     // set servo position
         Servo4.writeMicroseconds(servo[8]*256+servo[9]);     // set servo position
         Servo5.writeMicroseconds(servo[10]*256+servo[11]);   // set servo position
         Servo6.writeMicroseconds(servo[12]*256+servo[13]);   // set servo position
         break;
       
       case 18498:                                            // HB - mode and PWM data for left and right motors
         Serialread();
         Leftmode=data;
         Serialread();
         LeftPWM=data;
         Serialread();
         Rightmode=data;
         Serialread();
         RightPWM=data;
         break;
         
       default:                                                // invalid command
         Serial.flush();                                       // flush buffer
    }
  }
}

void Serialread() 
{//---- Read serial port until data has been received ---------------
  do 
  {
    data=Serial.read();
  } while (data<0);
}
    






void I2Cmode()
{//----------------- Your code goes here -------------------------

}



« PreviousNext »