CGI Server control Ultrasonic Sensor and I2C LCD on Raspberry Pi

Environment

  • Raspberry Pi 3B+
  • Raspbian GNU/Linux 9.4
  • Python 3
  • HC-SR04 Ultrasonic Module
  • 3.3V-5V Logic Level Converter CYT1076
  • SunFounder I2C LCD Module Display 16×2

Code

Main python file. Place on “/var/www/cgi-bin”.

CSS example. Place on “/var/www/html”.

/* raspi_cgi_server.css */
table, th, td {
  border-collapse: collapse;
  border: 1px solid #ccc;
  line-height: 1.5;
}

table th {
  width: 150px;
  padding: 10px;
  font-weight: bold;
  vertical-align: top;
  background: #3f3f3f;
  color: #ffffff;
}

table td {
  width: 350px;
  padding: 10px;
  vertical-align: top;
}

Result

Reference