<commit_before>---
layout: post
comments: true
title: Data transfer between HM-10 and Android
tags: [Android, Arduino, Bluetooth]
---

HM-10 bluetooth module is the most common BT module for Andruino. Chances are that if you're working on sending or receiving data via bluetooth with Arduino you'll be using the HM-10 module. 

Now, there are loads of articles and tutorials directing how to make an app which will connect to the module and send/ receive data hence I won't be rewriting that. What this post is about how I overcame a problem with respect to data transfer between HM-10 and Android app with a simple fix.

**Problem** - Data being accepted getting jumbled up to the point where the data made no sense. Example, the module emits data like this - 
`0,501,486,995;` But the android device receives the data like this - `,496,482,995;0,503,488,995;0,501,486,995;0,496,480,996;0,502,486,995;0,501,486,995;0,502,486,995;0,501,486,995;0,503,487,995;0,` or `996;,474,`.

The code to accept data is usually similar to this - 

    private void getDataFromDevice() {

    	byte[] buffer = new byte[256];  // buffer store for the stream
    	int bytes; // bytes returned from read()<commit_msg>Minor fix.<commit_after>---
layout: post
comments: true
title: Data transfer between HM-10 and Android
tags: [Android, Arduino, Bluetooth]
---

HM-10 bluetooth module is the most common BT module for Andruino. Chances are that if you're working on sending or receiving data via bluetooth with Arduino you'll be using the HM-10 module. 

Now, there are loads of articles and tutorials directing how to make an app which will connect to the module and send/ receive data hence I won't be rewriting that. What this post is about how I overcame a problem with respect to data transfer between HM-10 and Android app with a simple fix.

**Problem** - Data being accepted getting jumbled up to the point where the data made no sense. Example, the module emits data like this - 
`0,501,486,995;` But the android device receives the data like this - `,496,482,995;0,503,488,995;0,501,486,995;0,496,480,996;0,502,486,995;0,` or `996;,474,`.

The code to accept data is usually similar to this - 

    private void getDataFromDevice() {

    	byte[] buffer = new byte[256];  // buffer store for the stream
    	int bytes; // bytes returned from read()
{'fraction_non_alphanumeric': 0.08507909362975631, 'fraction_numerical': 0.08294142796066695, 'mean_word_length': 4.211581291759465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1885983', 'n_tokens_mistral': 815, 'n_tokens_neox': 660, 'n_words': 332}