Wireless Chat using Arduino & NRF24L01+ 2.4GHz RF Transceiver

It has been quite some time since I’ve tinkered with an Arduino, and this go around I decided to learn something new.

The NRF24L01 2.4GHz Transceiver is an extremely affordable wireless chip, I managed to pickup 10 units for around $12. This chip allows sending and receiving on the 2.4GHz wireless band.

Lucky for us there is a great Arduino library just waiting to be imported, thanks maniacbug!

So what did I set out to accomplish you ask? Why a chat application of course!

Components

Source Code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   9
#define CSN_PIN 10

const byte Address[5] = {'N','e','s','s','y'};

RF24 radio(CE_PIN, CSN_PIN);

String username = "";
String dataInput;
char dataToSend[32];
char dataReceived[32];


void setup() {
    Serial.begin(9600);
    Serial.println("Enter username...");
    
    radio.begin();
    radio.setDataRate(RF24_250KBPS);
    radio.setRetries(3, 5);
    radio.openWritingPipe(Address);
    radio.openReadingPipe(1, Address);
}


void loop() {

  // set username
  while (username == "") {
    if ( Serial.available() ) {
      username = Serial.readStringUntil('\n');
      Serial.print("Welcome ");
      Serial.println(username);
    }
  }

  // listen for radio data
  radio.startListening();
  
  if ( radio.available() ) {
    // read data from radio
    radio.read( &dataReceived, sizeof(dataReceived) );
    Serial.println(dataReceived);  
  }

  if( Serial.available() ) {
    // stop listening on radio
    radio.stopListening();
     
    // get serial input
    dataInput = "[" + username + "] " + Serial.readStringUntil('\n');
    Serial.println(dataInput);
    dataInput.toCharArray(dataToSend, 32);

    // send data
    radio.write( &dataToSend, sizeof(dataToSend) );  
  }
  
}

Using Magic the Gathering Art for D&D Ideas

Recently I’ve spent a bit time reading some of Dragon+ Magazine articles, one particularly grabbed my attention. Using Magic Cards as D&D Items presents a very interesting way to craft items, using Magic the Gathering cards, one can gain inspiration for their next +1 Dagger, or even an Elven Stronghold.

I think the reason I so quickly latched on to this idea was because Magic the Gathering and Dungeons & Dragons are two of my favorite games, plus I really dig the Ixala art work, I mean who hasn’t fantasized about riding a dinosaur to work.

Now I absolutely own tons of Magic the Gathering cards, and I could easily grab a handful and start coming up with an epic dungeon delve, but I thought, why not include a little bit of technology.

Lucky for me, I was able to recycle much of the work I did on Dungeon Brawl to make Magic Inspiration. So just what exactly is Magic Inspiration? Using this application, a Game Master can easily gain inspiration using Magic the Gathering artwork. Then when the ideas come flooding in, weave an amazing story.

It’s time to give credit where credit is due, this application was only made possible using Scryfall‘s bulk data. These people truly provide an awesome dataset!

Anyways, please feel free to grab the application from my Github, and let me know what you think.

Until next time. . .

Python Pandas and D&D Monsters

As you may be aware the Dungeon Brawl application I’ve been working on defines monsters in YaML format (check out the data/monsters directory).

I thought it would be interesting to load this data in to Pandas and do a bit of data analysis.

Loading Data

While in the Dungeon Brawl repository I started up an ipython shell,
then import a couple libraries:

In [1]: import yaml

In [2]: import glob

In [3]: import pandas

Next I need to find each of my monster’s YaML documents, these files reside in the data directory.

Using the glob library I can easily find all files in the directory with the .yaml extension:

In [4]: files = glob.glob('data/monsters/*.yaml')

I’m now able to iterate over each of my files, open them, parse them as YaML, then store the results in a new list:

In [5]: data = []

In [6]: for _file in files:
...:        raw = open(_file).read()
...:        data.append(yaml.load(raw))

The data list now contains a dictionary for each of my monsters:

In [7]: len(data)
Out[7]: 762

In [8]: data[0]['name']
Out[8]: 'Empyrean'

All that is left is to load this data into a Pandas DataFrame:

In [9]: df = pandas.DataFrame(data)

Analyzing

One of the first things I checked was the average hit points and armor class of a monster by challenge rating:

I then dug a bit deeper into each of the stats using the Pandas describe method, this gives things like standard deviation, mean, min, and max.

Below are a couple attempts as useful describe tables:

Hit Points by Challenge Rating

Armor Class by Challenge Rating

Challenge Rating by Monster Type

Hit Points by Monster Size

Challenge Rating by Monster Size

Well that is it, hope you found something in this post interesting.

Android Open Trivia Database Application

This month I went from owning an iPhone to an Android, I also decided to freshen up on the new hotness in the Android development realm.

I learned Kotlin is now an officially supported Language, Android Studio works much better than the old days of Eclipse and plugins, and OkHttp + Gson make interacting with Rest APIs pretty darn easy.

So what did I manage to create?

Using a list of public-apis found on toddmotto’s Github I came across the Open Trivia Database.

And there you have it I decided to develope a simple Trivia application:

The source code for this project can be found on my Github, Keep in mind I merely hacked this project together with no former Kotlin, and very little Android development experience.