Design a site like this with WordPress.com
Get started

I just released my first Python Project on Git.

Emphasis

Reads in a plaintext file from the command line. Outputs a randomly emphasized and bolded HTML5 file by adding either <b></b> or <i></i> tags to random words.

use

$~ python3 emphasize.py text.txt > emphasized_text.txt

Example output

text.txt Slouching away from the twisted sheets no laundered item rested on the chair, or layed neatly folded in oak drawers, or layed dirty on the floor. Beyond comprehension clothing I own had vanished. I wore the pair of jeans slept in, a red hoodie and blue sports coat paired with black slippers out the door late. The heat built-up in Spring. It was humid and I could feel the skipped shower manifesting itself within the aroma of my unwashed clothes. One shoe worn down to the skin. The other talking. Jeans slightly sagged from sweat and the sun shown hard into the corneas of my eyes.

newtext.html


    <!doctype html>

    <html lang="en">
    <head>
    <meta charset="utf-8">

    <title>Emphasize.py</title>
    <meta name="description" content="The HTML5 Herald">
    <meta name="author" content="SitePoint">

    <link rel="stylesheet" href="css/styles.css?v=1.0">

    </head>

    <body>
    
Slouching away <em>from</em> the <b>twisted</b> <em>sheets</em> no laundered item rested <em>on</em> the <em>chair,</em>
or <em>layed</em> neatly folded <em>in</em> <em>oak</em> drawers, <b>or</b> layed <b>dirty</b> <em>on</em> <em>the</em> floor.
<b>Beyond</b> <em>comprehension</em> clothing I own <em>had</em> <b>vanished.</b> <b>I</b> <em>wore</em> the pair of jeans
<b>slept</b> in, <b>a</b> red hoodie and blue sports coat <em>paired</em> <b>with</b> <b>black</b> slippers <b>out</b>
the <b>door</b> late. The heat built-up in Spring. It <b>was</b> humid <em>and</em> <b>I</b> <em>could</em> <em>feel</em>
the skipped shower <b>manifesting</b> itself within <b>the</b> aroma <b>of</b> <em>my</em> unwashed clothes.
One shoe worn <b>down</b> to <b>the</b> skin. <em>The</em> <b>other</b> <b>talking.</b> <em>Jeans</em> slightly sagged <em>from</em>
<em>sweat</em> and <em>the</em> sun shown hard into <em>the</em> corneas <em>of</em> <em>my</em> <b>eyes.</b>
</body></html>

Rendered

Slouching away from the twisted sheets no laundered item rested on the chair, or layed neatly folded in oak drawers, or layed dirty on the floor. Beyond comprehension clothing I own had vanished. I wore the pair of jeans slept in, a red hoodie and blue sports coat paired with black slippers out the door late. The heat built-up in Spring. It was humid and I could feel the skipped shower manifesting itself within the aroma of my unwashed clothes. One shoe worn down to the skin. The other talking. Jeans slightly sagged from sweat and the sun shown hard into the corneas of my eyes.

Note

Firefox does not always render em tags without a CSS file.

Download

Code located at http://github.com/bbevan/Emphasis. Clone the repository with

$:~/Emphasis$ mkdir Emphasis
$:~/Emphasis$ git clone https://github.com/bbevan/Emphasis.git
Cloning into 'Emphasis'...
remote: Enumerating objects: 31, done.
remote: Counting objects: 100% (31/31), done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 31 (delta 10), reused 24 (delta 6), pack-reused 0
Unpacking objects: 100% (31/31), done.

..or download the .zip located @ https://github.com/bbevan/Emphasis/archive/master.zip

# todo * Write more unit tests. * Repair bugs in unit tests for errors generated by the random nature of some methods. * Refactor methods based on functionals.

Advertisement

avrdude: stk500_recv(): programmer is not responding

While uploading a sketch to my Arduino Nano board from Ubuntu 19.10 with an I2C LiquidCrystal Display attached to the board, I received the following error.

avrdude: stk500_recv(): programmer is not responding

The sketch failed to upload.

Solution

Disconnect the LCD-I2C device from ground. Re-upload the sketch.

I’m not sure why this works, or what causes the error, but disconnecting ground from the screen will power it down, and the upload will pass through provided your user has access to the /dev/ttyUSB0 device.

If not, check to see if the Linux system has created the device under another name, such as /dev/ttyUSB1 .

Fuzzing FPGA synthesis tools — John’s Blog

When you want to do some computation on an FPGA, it is traditional to enter your design in a language like Verilog, and then to use automatic synthesis tools to turn your Verilog design into a “configuration bitstream” that can be fed to your FPGA to make it perform the computation you want. These synthesis […]

Fuzzing FPGA synthesis tools — John’s Blog

A fuzzer is a program that generates random input for another piece of software. The random inputs produce bugs in the target software, oftentimes a crash, but sometimes a security flaw. They’re useful for analyzing the robustness and correctness of a computer program’s capability to handle arbitrary user input.

John Wickerson & his students wrote a fuzzer for FPGA (Field Programmable Gate Array) boards, churning out random Verilog programs for input into the IDE’s logic synthesizer. The logic synthesizer’s job is to turn high-level Verilog code into low-level logic , flipping the FPGA gates into proper configuration, i.e. a hardware implementation of the code. The study determines how often the synthesizer fails to turn Verilog code into the proper gate arrangement on the board. They also find different classes of bugs produced by the fuzzed synthesizer.

It’s a very interesting article. If you are not familiar with FPGA development, take a look at this link from Xilinx.

Arduino Dip-Switch Binary Adder

  • Wire the Dip-switches to ground on one side with 1Kohm resistors.
  • Wire the Dip-switches to Digital and Analog input pins D7-D10, A0-A3
  • UseINPUT_PULLUP in the code to indicate the negative wiring.
  • Treat the Analog input pins as digital by using digitalRead() instead of analogRead() .
  • Wire the LCD according to instructions found here on the Arduino.cc website.
  • The left Dip-switch acts as input for the first binary integer. The second Dip-switch acts as input for the second binary integer.
  • Two different functions, digital_binary_to_int(), analog_binary_to_int() convert the binary inputs to decimal.
  • The Arduino adds the two decimal numbers together & displays them on the LCD screen.

The Code

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup()
{
  
  // Digital Pins 10,9,8,7 are for binary input 
  // for the left Dip-Switch.
  
  // INPUT_PULLUP is used since the DipSwitches
  // are wired to ground.
  pinMode(10, INPUT_PULLUP);
  pinMode(9,  INPUT_PULLUP);
  pinMode(8,  INPUT_PULLUP);
  pinMode(7,  INPUT_PULLUP);
  
  // Analog Pins A0, A1,A2, A3 are for binary input
  // for the right Dip-Switch.
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1,  INPUT_PULLUP);
  pinMode(A2,  INPUT_PULLUP);
  pinMode(A3,  INPUT_PULLUP);
  
}

int digital_binary_to_int()
{
  int a = digitalRead(10);
  int b = digitalRead(9);
  int c = digitalRead(8);
  int d = digitalRead(7);
  
  return a*1 + b*2 + c*4 + d*8;
}

int analog_binary_to_int()
{
  float a = floor(digitalRead(A0));
  float b = floor(digitalRead(A1));
  float c = floor(digitalRead(A2));
  float d = floor(digitalRead(A3));
  
  return d*1 + c*2 + b*4 + a*8;
}

void loop()
{
  String output_add;
  int x = digital_binary_to_int();
  int y = analog_binary_to_int();
  int ans = x + y;
  
  output_add = String(ans);
  lcd.begin(16,2);
  lcd.print(output_add);
}

Operation

0101 + 1001
Remember to check the Endian configuration.

Link to the TinkerCad Project

https://www.tinkercad.com/things/cCDSb54Jqhv-copy-of-binary-adder/editel?tenant=circuits?sharecode=CB-ngCQZsJd8bXSJav8qYv6HcbWj-O3l5EQ-vD7t_30=

Arduino Serial Access on Ubuntu

When I moved over to Ubuntu a few months ago, I was in the middle of an Arduino project involving the LCD display of strings via Python’s serial module. On my windows device, the board was accessed via Window’s Comport 3 (COM3), however Linux does not use that nomenclature as the serial device software is different.

According to Building Embedded Linux Systems: Concepts, Techniques, Tricks, and Traps by Yaghmour et al., serial devices are “uniformly accessed as terminal devices”. Those devices are found under /dev/ttyS0 all the way through /dev/ttyS191 (pg. 73).

The problem is that my Python script bugged out an error upon executing the following code.

import serial
ser=serial.Serial("/dev/ttyS0", 9600) #9600 baud connection to the board via the serial port on /dev/ttyS0
ser.write("My string.")

The error stated that I had no user rights to access /dev/ttyS0 for a couple of reasons. One, that’s the wrong serial device, and two, Ubuntu keeps serial access under a different location for USB devices.

The Solution

Ubuntu keeps USB serial device access under /dev/serial/by-id/. My working code for a legitimate Arduino Uno looked something like this a few days ago.

import serial
ser=serial.Serial("/dev/serial/by-id/arduinosomethingsomethingusb", 9600) #9600 baud connection to the board via the serial port on /dev/serial/by-id/arduinosomethingsomethingusb
ser.write("My string.")

The exact code I used for my bootleg Arduino Nano looked similar. Under a sudo python shell:

>>> import serial
>>> ser=serial.Serial("/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0", 9600)
>>> ser.write("test")
4

I noted that usb-1a86_USB2.0-Serial-if00-port0 did not exist until I plugged in the board, and was created on the fly by the system once powered on.

Access

Some users report problems accessing serial devices on Ubuntu 18. My experience on Ubuntu 19.10 was different once I gave Python root permission through sudo. Perhaps the issue is fixed in the new release. While searching the release notes, I couldn’t find any mention of serial devices, although there is new support for Raspberry Pi, which may have repaired the issue for the Arduino.