Broadcast Engineer at BellMedia, Computer history buff, compulsive deprecated, disparate hardware hoarder, R/C, robots, arduino, RF, and everything in between.
4240 stories
·
4 followers

Create a Discord Webhook with Python for Your Bot

1 Share

Discord is an IRC-like chat platform that all the young cool kids are hanging out on. Originally intended as a way to communicate during online games, Discord has grown to the point that there are servers out there for nearly any topic imaginable. One of the reasons for this phenomenal growth is how easy it is to create and moderate your own Discord server: just hit the “+” icon on the website or in the mobile application, and away you go.

As a long-time IRC guy, I was initially unimpressed with Discord. It seemed like the same kind of stuff we’ve had for decades, but with an admittedly slick UI. After having used it for a few months now and joining servers dedicated to everything from gaming to rocket science, I can’t say that my initial impression of Discord is inaccurate: it’s definitely just a modern IRC. But I’ve also come to the realization that I’m OK with that.

But this isn’t a review of Discord or an invitation to join the server I’ve setup for my Battlefield platoon. In this article we’re going to look at how easy it is to create a simple “bot” that you can plug into a Discord server and do useful work with. Since anyone can create a persistent Discord server for free, it’s an interesting platform to use for IoT monitoring and logging by simply sending messages into the server.

A Practical Example

Weather bot posting to my Discord channel

I don’t want to get too bogged down with the specifics of how you can use Discord in your project, I leave that up to the reader’s imagination. But as an example, let’s say you wanted to create a weather monitoring station that would post the current temperature and a picture of the sky to your Discord server every hour or so.

Let’s also say that the temperature sensing is happening in the background and is available to our code as the variable CURRENT_TEMP, and that the image "latest_img.jpg" is also automatically popping up in the current directory where our Python script can get to it.

Setting Up the Discord Server

As mentioned previously, setting up a Discord server is exceptionally easy. All you really have to do is give the thing a name and click “Create”. Incidentally, you should setup the server on your computer via the Discord web interface, as not all of the options mentioned below are currently available from the mobile applications.

Once you’ve created it, you then need to go into the server settings for webhooks. This is where you will create your webhook entries and get the authentication tokens that your script will need to send messages into the server.

Each webhook needs its own name, and you can give them individual icons to pretty things up a bit. The configuration will also ask you what channel you want the webhook to have access to, which let’s you subdivide things nicely if you plan on having a lot of data get dumped into the server.

The final part of the webhook configuration is the most important, as it gives you the URL the webhook will use. The URL contains the authentication token and ID:

discordapp.com/api/webhooks/WEBHOOK_ID/WEBHOOK_TOKEN

Software Environment

As previously mentioned, I’ll be doing this in Python since that’s also what the cool kids are doing this days. There are Discord libraries available for pretty much any language you can think of though, so if you want to do something similar in your language of choice it shouldn’t be a problem and the server-side setup will still look the same.

The two libraries required are the ever popular Requests, which will handle the HTTP side of things for us, and discord.py which is the most popular Discord API wrapper for Python. Note that we need to use the development version of discord.py for this to work, as the stable build doesn’t currently have webhook support.

The Code

It’s actually quite simple to send a message into the Discord server with these libraries, and a basic implementation only takes a few lines:

#!/usr/bin/env python3
import requests
import discord
from discord import Webhook, RequestsWebhookAdapter, File

# Create webhook
webhook = Webhook.partial(WEBHOOK_ID, WEBHOOK_TOKEN,\
 adapter=RequestsWebhookAdapter())

# Send temperature as text
webhook.send("Current Temp: " + CURRENT_TEMP)

# Upload image to server
webhook.send(file=discord.File("latest_img.jpg"))

That’s all there is to it. Executing that code should send a message into the Discord server from the webhook bot created earlier.

Final Thoughts

Automatically generated stats posted to Discord

Discord has native applications for all major mobile and desktop operating systems, as well as a very polished web interface that you can use from any computer with a modern web browser without having to install anything. This ubiquity and ease-of-use make it an interesting platform for more than just chatting about games. Using Discord for remote monitoring and logging means that you, and anyone you wish to invite, can get instantaneous notifications and updates about anything you want.

Personally, I’m using a similar setup to post automatically generated stats for my Battlefield platoon directly into our Discord chat every Friday morning with a couple of Python scripts and a cron job running on a Pi Zero. But the only real limit is your imagination.











Read the whole story
tekvax
18 hours ago
reply
Burlington, Ontario
Share this story
Delete

Laser Galvo Control via Microcontroller’s DAC

1 Share

Mirror galvanometers (‘galvos’ for short) are the worky bits in a laser projector; they are capable of twisting a mirror extremely quickly and accurately. With two of them, a laser beam may be steered in X and Y to form patterns. [bdring] had purchased some laser galvos and decided to roll his own control system with the goal of driving the galvos with the DAC (digital to analog) output of a microcontroller. After that, all that was needed to make it draw some shapes was a laser and a 3D printed fixture to hold everything in the right alignment.

The galvos came with drivers to take care of the low-level interfacing, and [bdring]’s job was to make an interface to translate the 0 V – 5 V output range of his microcontroller’s DAC into the 10 V differential range the driver expects. He succeeded, and a brief video of some test patterns is embedded below.

Instagram Photo

We have seen drawing shapes with lasers go in some really creative and interesting directions. For example, this amazing mechanical laser projector draws shapes using only 3D printed cams and gears, and this one draws on a glow-in-the-dark surface with a UV laser for a ghostly take on things.





Read the whole story
tekvax
18 hours ago
reply
Burlington, Ontario
Share this story
Delete

The uA723 As A Switch Mode Regulator

1 Share

If you are an electronic engineer or received an education in electronics that went beyond the very basics, there is a good chance that you will be familiar with the Fairchild μA723. This chip designed by the legendary Bob Widlar and released in 1967 is a kit-of-parts for building all sorts of voltage regulators. Aside from being a very useful device, it may owe some of its long life to appearing as a teaching example in Paul Horowitz and Winfield Hill’s seminal text, The Art Of Electronics. It’s a favourite chip of mine, and I have written about it extensively both on these pages and elsewhere.

The Fairchild switching regulator circuit. From the μA723 data sheet in their 1973 linear IC databook, page 194 onwards.
The Fairchild switching regulator circuit. From the μA723 data sheet in their 1973 linear IC databook, page 194 onwards.

For all my experimenting with a μA723 over the decades there is one intriguing circuit on its data sheet that I have never had the opportunity to build. Figure 9 on the original Fairchild data sheet is a switching regulator, a buck converter using a pair of PNP transistors along with the diode and inductor you would expect. Its performance will almost certainly be eclipsed by a multitude of more recent dedicated converter chips, but it remains the one μA723 circuit I have never built. Clearly something must be done to rectify this situation.

Looking at the circuit and referring to the data sheet, it becomes obvious that the μA723 is configured as an oscillator through the feedback provided by the 1 MΩ resistor R4. Extra loop gain is provided by the combination of the PNP Darlington pair of external transistors and the μA723’s internal output transistor, and pulse-width modulation is achieved through the internal comparator seeing the output voltage on its inverting input in comparison to the reference voltage derived through R1 and R2. The resulting oscillation switches the current into the network composed of D1, L1, and C2, forming a textbook buck converter.

Dusting Off an Old Circuit Design

Fifty years has passed since that data sheet was published, and in that time the electronics industry has moved on to the extent that many of today’s components would be unrecognisable to an engineer from the 1960s. The resistors and capacitors perform the same function, but the μA723 is a rare survivor in semiconductor catalogues while the two transistors and the diode have passed into history. Meanwhile there are a plethora of ready-wound inductors to replace the suggested hand-wound one in the original.

To build a μA723 switcher for 2018 then it is necessary to perform a few searches for modern equivalents to the 1967 parts. For the semiconductors, this means taking a look at the data sheets for the originals, and matching modern parts with similar gain, current handling, power dissipation, and speed. I settled upon the 2N4403 as a replacement for the 2N5545 and an MPS751 as a 2N5153 equivalent, though since transistors have improved so much in five decades I could have picked from many others. You’d expect the diode to be a fast rectifier, and I settled upon a 1N4837. The most recent Texas Instruments datasheet has an unexpected choice though in a 1N4005 general purpose rectifier, so perhaps speed isn’t as critical after all. There are multiple manufacturers of inductors suitable for small buck converters, the Taiyo Yuden part I selected is simply one of many.

My take on the 723 switcher, on a Boldport Club board.
My take on the μA723 switcher, on a Boldport Club board.

Building the circuit took advantage of a recent Boldport Club project, a μA723 dev board and Widlar tribute. Regular Hackaday readers will know Boldport’s Saar Drimer for his distinctive artistic PCB design, and the Widlar project is typical of his aesthetic. The switcher takes it slightly off-piste, but the board has been designed to accommodate any circuit. Time for a bit of responsible disclosure: it’s a board I’m intimately familiar with because Saar asked me to write its instructions when he designed it a few months ago.

My take on prototype construction is a little rough-and-ready, and I apologise if it offends your delicate electronic sensibilities. A mixture of through-hole and pads on the board to support a piecemeal spider-web of components, it’s not exactly pretty. It places the voltage reference divider R1/R2 and associated components to the left of the μA723, the inductor and diode above it, and the two transistors to its right. The divider is chosen for a 5 V output, and the 1 MΩ feedback resistor loops in an ungainly manner over the top of the chip.

Success, Partially

Astoundingly, my μA723 switcher build worked on first switch-on, rewarding me with a 5.01 V DC output into a 50 Ω load from my 12 V input. Connecting up the oscilloscope though revealed another side to this regulator though, and demonstrated why you might rarely see a μA723 in this configuration.

The yellow trace shows ripple on the DC output, while the blue one shows the waveform at the transistor collectors.
The yellow trace shows ripple on the DC output, while the blue one shows the waveform at the transistor collectors.

The yellow trace in the screenshot to the right shows the ripple on the DC output, while the blue trace shows the waveform on the transistor collectors. The circuit is oscillating at just over 100 kHz, higher than might be expected until it is realised that the whole thing is a free-running with a frequency dictated only by the characteristics of its loop rather than being derived from a separate oscillator as might be the case in a more recent design.

The 260 mV peak-to-peak ripple on the DC output is the killer with this circuit, an unacceptably high figure for all but the most undemanding of applications. It provides an object lesson in how more recent devices with significant thought put into how they handle their PWM generation have improved performance in this respect. I’d urge anyone with an interest in this topic to read some of the Linear Technology application notes written by Jim Williams, particularly AN35 and AN29. Despite the free-running μA723’s rather basic PWM generation, it is easily possible to see the duty cycle change with the conditions. Dropping the input voltage to just before it starts to lose regulation at a rather high value of about 9 V, the duty cycle increases from 50% to about 70%.

So the μA723 is no star as a switching regulator, which is hardly surprising. There is another feature of the circuit that makes it entirely unsuitable for a modern environment, being a somewhat powerful 100 kHz source it produces a significant quantity of RF radiation. An AM radio anywhere within range is wiped out as soon as it is powered up, reminiscent of the effect of some older CRT TV sets. It’s extremely unlikely that this would make it through an EMC test.

This has been an interesting foray into switching regulator construction and a chance to fill that last gap in the μA723 data sheet. It’s a design that works, but one has the sense that it made it to the data sheet because the chip had the capability rather than because it was a sensible choice even by the standards of 1967. One wonders whether this is a hardware hack from Bob Widlar, pushing the chip beyond its design, one that has survived beyond expectation in every μA723 data sheet since. If that is the case then I metaphorically take off my hat to him, it’s a circuit I wouldn’t have had the chutzpah to publish had I been the sheet’s author.











Read the whole story
tekvax
18 hours ago
reply
Burlington, Ontario
Share this story
Delete

Retrotechtacular: AM Radios, Core Memory, And Color TV, What Was Hot In Chips In ’73

1 Share

As part of writing tech stories such as those we feature here at Hackaday, there is a huge amount of research to be done.  We trawl through pages and pages of obscure blogs, videos, and data sheets. Sometimes we turn up resources interesting enough that we file them away, convinced that they contain the nucleus of another story at some point in the future.

Today’s topic of entertainment is just such a resource, courtesy of the Internet Archive. It’s not a video as we’d often provide you in a Retrotechtacular piece, instead it’s the February 1973 edition of the Fairchild Semiconductor Linear Integrated Circuits Catalog. Books like this one that could be had from company sales representatives were highly prized in the days before universal Internet access to data sheets, and the ink-on-paper datasheets within it provide a fascinating snapshot of the integrated electronics industry as it was 45 years ago.

The first obvious difference between then and now is one of scale, this is a single volume containing Fairchild’s entire range. At 548 pages it wouldn’t have been a slim volume by any means, but given that Fairchild were at the time one of the big players in the field it is unimaginable that the entire range of a 2018 equivalent manufacturer could be contained in the same way. Given that the integrated circuit was at the time an invention barely 15 years old, we are looking at an industry still in relative infancy.

The catalog has a series of sections with familiar headings: Operational amplifiers, comparators, voltage regulators, computer/interface, consumer, and transistor/diode arrays with analog switches. Any modern catalog will have similar headings, and there are even a few devices you will find have survived the decades. The μA741 op-amp (page 64) from its original manufacturer has not yet become a commodity product here, and it sits alongside familiar devices such as the μA7800 series (page 201) or μA723 (page 194) regulators.

The uA702 circuit has a real simplicity to it.

The op-amp chapter reads almost as a potted history of the development of these components as integrated circuits from Bob Widlar’s original μA702 (Page20, labeled as a “DC amplifier” here) through its improved siblings to the familiar frequency-compensated μA741 that we’ve already mentioned, and thence into the realm of FET input devices. Op-amps are a field that is still developing, but in these pages and over just that decade’s development we see their genesis.

Power supply regulators in 1973 are exclusively linear, in sharp contrast to the array of switching regulators that would grace a similar chapter today. This section shows a field in its relative infancy, in which a 3-terminal μA7800 series regulator was still a big deal, and in which the μA723’s switching application circuit is an oddity rather than its primary application. One surprise comes from the negative versions of the three-terminal regulators, what we would know as a 7900-series chip is instead a 78N00-series (page 238). Did 7900-series chips debut from a rival manufacturer? Perhaps readers would like to speculate in the comments.

The computer interface chapter is a selection of line drivers, RS232 interfaces, display drivers, and A to D converters. Some of these functions are still available in today’s catalogues, but it’s fair to say that computer interfacing has moved on since the 1970s. An archaic set of items though are the core memory drivers and sense amplifiers starting with the 75325 on page 318. Core memory was out-of-date by 1973 and is now something of a curio, so these data sheets make particularly interesting reading for the student of computing hardware history.

A complete NTSC color decoder in 3 chips. When you could still buy sets doing this with discrete components, this was a very big deal indeed.

The last-but-one chapter shows us 1973 at its finest, or perhaps some of the 1973 those of us who were alive at the time might remember. The functions in Fairchild’s consumer product line are entirely analogue, and reflect the state-of-the-art in what the well-to-do family might have wished for in their living room or car.

A CRT color TV and a stereo FM radio were both big-ticket items in the early 1970s, and though home computers had arrived by the end of the decade they would remain supreme in the world of home entertainment for many years to come. Thus we have entire chipsets for the small-signal and color decoder sections of NTSC (shown here from page 458) and PAL TVs, triple video op-amps for color CRT drivers, stereo multiplex decoders both analog and PLL, and entire AM radios on a chip, but not a digital IC to be seen. Uniquely among all the chapters in the book this one has no survivors into the present day, even those chips that might still find a use have been superceded many times over.

Finally, we’re on familiar ground with a chapter of transistor arrays, diode arrays, and a single analog switch. The 3046 transistor array (page 499) should be a familiar part as it is still available, and it serves to highlight something else about the Fairchild range. In most of the chapters are these parts with just a number and no letters, these are Fairchild’s take on a competitor’s device. Thus for example the 3046 is RCA’s CA3046, and in the op-amp chapter the 301 is National Semiconductor’s LM301. Given that the 301 was the work of [Bob Widlar] when he left Fairchild for National, there must have been some internal politics over the cloning of that particular part.

In 1973 many pieces of electronics were entirely made from discrete components and it was still possible to buy consumer electronic devices containing germanium transistors or even tubes, so this catalog gives us the state of the art in linear circuitry rather than a universal picture. It makes an interesting read for its insights into archaic technologies as well as for its look at some of the semiconductor industry’s component survivors, and it would still find a place on the shelves of a Hackaday writer, were she to find a physical copy. We have come a long way since 1973, but there is still value sometimes in looking back.











Read the whole story
tekvax
18 hours ago
reply
Burlington, Ontario
Share this story
Delete

Behold the cacophonous Furby Organ

1 Share

Looking remarkably like the Mogwai creatures from the 1984 film Gremlins, Furbies first hit the market in November 1998, becoming an instant success. In just the first three years of production, over 40M of these fake fur-covered robotic toys were sold. Since their early days, the Furby has been re-introduced a few times.

That means there are a lot of Furbies collecting dust on this planet.

Well, musician and inventor Sam Battle of Look Mum No Computer salvaged over 44 of them and attached them to an organ. Watch the video to hear a cacophony of "Furbish" music (?).

I won't lie, as noisy as it is, I totally want a Furby Organ for myself.

Read the whole story
tekvax
18 hours ago
reply
Burlington, Ontario
Share this story
Delete

Expect Northern Lights and power grid fluctuations this week

1 Share

Good news! This week, folks living in as far north as Michigan may get treated to a stunning light show as Auroras will be shining brighter and further away from the planet’s axis than usual. What a rare treat! The bad news: the same phenomenon that causes the Northern Lights to do their thing could also screw with a few important technologies that we rely on, every day.

According to Seeker.com, the National Oceanic and Atmospheric Administration has stated that charged solar particles, the result of a ‘moderate’ solar flare barfed out of the Sun on February 12 could cause minor fluctuations in power grids and have an impact on communications with satellites that are currently orbiting the earth. In her story on the issue, Seeker’s Elizabeth Howell took the time to explain how the particles are created:

Solar flares and particle ejections are associated with sunspots — dark areas on the sun's surface — that host intense magnetic activity. As the magnetic fields in a sunspot cross, NASA stated, this can cause a sudden energy explosion, also known as a solar flare. This sends radiation out into space.

Sometimes these explosions can also send off charged particles, which are called coronal mass ejections or CMEs. "CMEs are huge bubbles of radiation and particles from the sun," NASA stated. "They explode into space at very high speed when the sun's magnetic field lines suddenly organize."

These bubbles of radiation generally bop off into space, away from the earth. But not this week.

Fortunately, the solar storm forecasters at NASA and NOAA believe that we won't take a huge hit from this latest solar storm. But, if you see the lights in your home flickering, you'll now know why. And hey, if the power does go out, you might be able to eat dinner by the Northern Lights.

Image: NASA Goddard Space Flight Center/Flickr

Read the whole story
tekvax
23 hours ago
reply
Burlington, Ontario
Share this story
Delete
Next Page of Stories