Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

cakraawijaya/Automatic-Items-Counter-on-STM8-based-Conveyor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Open Source Love License: MIT GitHub last commit Project Type

Automatic-Items-Counter-on-STM8-based-Conveyor

Automatic items counter is a fast and precise tool for humans to get the sum of items. The purpose of this project is to provide education to the wider community on how to make a simple automatic item counter. This project has been implemented and took approximately 2 weeks. This system is made to be used as a complement to the conveyor. In addition, this system has also provided display and reset features for the needs of its users. The way this system works is that if the items transported by the conveyor are right in front of the laser beam, the light intensity received by the LDR sensor is low, so it is considered that there are items and starts counting. The calculation results will be displayed on the LCD screen. This project will be useful for business people, because it can increase efficiency in production. The results show that this system can function properly.



Project Requirements

Part Description
Development Board STM8S103F3P6
Code Editor Arduino IDE
Programmer Tools ST-Link/V2
Serial Communication Tools FTDI USB
Driver • ST-Link USB Driver
• CDM FTDI USB Driver
Communications Protocol Inter Integrated Circuit (I2C)
Programming Language C/C++
Arduino Library LiquidCrystal_I2C (default)
Sensor • LDR Sensor Module (x1)
• KY-008: Laser Transmitter Module 5V (x1)
Display LCD I2C (x1)
Other Components • Micro USB cable - USB type A (x1)
• Mini USB cable - USB type A (x1)
• Jumper cable (1 set)
• Adaptor DC 5V (x1)
• Breadboard (x1)
• Push button 12 x 12 mm



Download & Install

  1. Arduino IDE

    https://bit.ly/ArduinoIDE_Installer
    

  2. ST-Link USB Driver

    https://bit.ly/STLink_USB_Driver
    

  3. CDM FTDI USB Driver

    https://bit.ly/CDM_FTDI_USB_Driver
    



Project Designs

Block Diagram Pictorial Diagram
block-diagram pictorial-diagram
Wiring
wiring



Scanning the I2C Address on the LCD

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial); // Wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  int nDevices = 0;
  Serial.println("Scanning...");

  for (byte address = 1; address < 127; ++address) {
    // The i2c_scanner uses the return value of the Wire.endTransmission to see if a device did acknowledge to the address.
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");

      ++nDevices;
    } else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  } else {
    Serial.println("done\n");
  }
  delay(5000); // Wait 5 seconds for next scan
}



Arduino IDE Setup

  1. Open the Arduino IDE first, then open this project by clicking File -> Open :

    auto_counter.ino


  2. Fill in the Additional Board Manager URLs in Arduino IDE

    Click File -> Preferences -> enter the Boards Manager Url by copying the following link :

    https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json
    

  3. Board Setup in Arduino IDE

    How to setup the STM8S103F3P6 board

    • Click Tools -> Board -> Boards Manager -> Install Sduino STM8 plain C core (non-C++).

    • Then click Tools -> Board -> STM8S Boards -> STM8S103F3 Breakout Board.


  4. Change Programmer in Arduino IDE

    Click Tools -> Programmer -> ST-Link/V2


  5. Before uploading the program please click: Verify.

  6. If there is no error in the program code, the next step is to use the STM8 programming tool according to the procedure. Then click: Upload.

  7. If there is still a problem when uploading the program, then try checking the driver / port / programmer tool / others section.



ST-Link/V2 Setup

stlink-configuration

Notes:

• The single wire interface module or SWIM is basically used to communicate with the STM8 board.

• You can see the wiring between the ST-Link/V2 and the STM8 board in detail in the picture above.

• Based on personal experience, the STM8 can only be programmed with ST-Link.



FTDI USB Setup

ftdi-configuration

Notes:

• Serial communication on this STM8 board is very possible, especially for Serial Monitor and Serial Plotter purposes. Tools that can be used for serial communication include: CP2102 USB, CH340 USB, FTDI USB, or with PL2303 USB.

• You can see the wiring between the FTDI USB and the STM8 board in detail in the picture above.

• Based on experience, I admit that using FTDI USB or CP2102 USB is much better than PL2303 USB or CH340 USB because they are known to be more stable in performance.



Removing write protection on STM8

The write protection on the STM8 can be removed through several steps, among others :

  1. Open CMD (Command Prompt).

  2. Enter into the directory :

    C:\Users\[Computer Name]\AppData\Local\Arduino15\packages\sduino\tools\STM8Tools\2019.02.05\win


  3. Input the command:

    stm8flash -cstlinkv2 -pstm8s103?3 -u
    

  4. Press Enter, then you can see the result as the picture below.

    rmv-protection



Get Started

  1. Download and extract this repository.

  2. Make sure you have the necessary electronic components.

  3. Make sure your components are designed according to the diagram.

  4. Configure your device according to the settings above.

  5. Please enjoy [Done].



Highlights

auto-items-counter



Appreciation

If this work is useful to you, then support this work as a form of appreciation to the author by clicking the ⭐Star button at the top of the repository.



Disclaimer

This application is my own work and is not the result of plagiarism from other people's research or work, except those related to third party services which include: libraries, frameworks, and so on.



LICENSE

MIT License - Copyright © 2024 - Devan C. M. Wijaya, S.Kom

Permission is hereby granted without charge to any person obtaining a copy of this software and the software-related documentation files to deal in them without restriction, including without limitation the right to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons receiving the Software to be furnished therewith on the following terms:

The above copyright notice and this permission notice must accompany all copies or substantial portions of the Software.

IN ANY EVENT, THE AUTHOR OR COPYRIGHT HOLDER HEREIN RETAINS FULL OWNERSHIP RIGHTS. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, THEREFORE IF ANY DAMAGE, LOSS, OR OTHERWISE ARISES FROM THE USE OR OTHER DEALINGS IN THE SOFTWARE, THE AUTHOR OR COPYRIGHT HOLDER SHALL NOT BE LIABLE, AS THE USE OF THE SOFTWARE IS NOT COMPELLED AT ALL, SO THE RISK IS YOUR OWN.